diff options
author | Pauli Virtanen <pav@iki.fi> | 2019-10-07 19:57:19 +0300 |
---|---|---|
committer | Pauli Virtanen <pav@iki.fi> | 2019-10-07 20:01:33 +0300 |
commit | ffb381aa18e93d30099bb97cf58435dd51d88bfa (patch) | |
tree | 54effbdb73cb11ab5488bd3378d76b0e3ddd37b6 /numpy/core/tests | |
parent | b8445583d506aeb9da3897801132279e977b4427 (diff) | |
download | numpy-ffb381aa18e93d30099bb97cf58435dd51d88bfa.tar.gz |
BUG: fix fromfile behavior when reading sub-array dtypes
Restore previous behavior of fromfile, by ensuring the original dtype is
used for reading, instead of the type of the created array which may
have sub-arrays collapsed.
Reverts parts of 454c5b5e9a76809a4ab60bda30aa048ec37ee11e
Diffstat (limited to 'numpy/core/tests')
-rw-r--r-- | numpy/core/tests/test_multiarray.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py index 88db357b2..9b124f603 100644 --- a/numpy/core/tests/test_multiarray.py +++ b/numpy/core/tests/test_multiarray.py @@ -5023,6 +5023,19 @@ class TestIO(object): self.test_tofile_sep() self.test_tofile_format() + def test_fromfile_subarray_binary(self): + # Test subarray dtypes which are absorbed into the shape + x = np.arange(24, dtype="i4").reshape(2, 3, 4) + x.tofile(self.filename) + res = np.fromfile(self.filename, dtype="(3,4)i4") + assert_array_equal(x, res) + + x_str = x.tobytes() + with assert_warns(DeprecationWarning): + # binary fromstring is deprecated + res = np.fromstring(x_str, dtype="(3,4)i4") + assert_array_equal(x, res) + class TestFromBuffer(object): @pytest.mark.parametrize('byteorder', ['<', '>']) |