diff options
author | Matti Picus <matti.picus@gmail.com> | 2019-09-08 17:05:52 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-08 17:05:52 +0200 |
commit | f786041db9697f58b087e18198561db8b28235c4 (patch) | |
tree | 677f6b90d2c867d2828ebc01cd9eb6afdf44b166 /numpy/core/tests | |
parent | 495d352bf325f44d78001f059d625123e49f027e (diff) | |
parent | d6f7524defc808f32219528350429d5569696183 (diff) | |
download | numpy-f786041db9697f58b087e18198561db8b28235c4.tar.gz |
Merge pull request #14393 from ahaldane/fix_fieldless_view_itemsize
BUG: view with fieldless dtype should raise if itemsize != 0
Diffstat (limited to 'numpy/core/tests')
-rw-r--r-- | numpy/core/tests/test_dtype.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/numpy/core/tests/test_dtype.py b/numpy/core/tests/test_dtype.py index f60eab696..f5ca775ef 100644 --- a/numpy/core/tests/test_dtype.py +++ b/numpy/core/tests/test_dtype.py @@ -419,6 +419,31 @@ class TestRecord(object): assert_raises(ValueError, np.dtype, {'formats': ['i4', 'i4'], 'f0': ('i4', 0), 'f1':('i4', 4)}) + def test_fieldless_views(self): + a = np.zeros(2, dtype={'names':[], 'formats':[], 'offsets':[], + 'itemsize':8}) + assert_raises(ValueError, a.view, np.dtype([])) + + d = np.dtype((np.dtype([]), 10)) + assert_equal(d.shape, (10,)) + assert_equal(d.itemsize, 0) + assert_equal(d.base, np.dtype([])) + + arr = np.fromiter((() for i in range(10)), []) + assert_equal(arr.dtype, np.dtype([])) + assert_raises(ValueError, np.frombuffer, b'', dtype=[]) + assert_equal(np.frombuffer(b'', dtype=[], count=2), + np.empty(2, dtype=[])) + + assert_raises(ValueError, np.dtype, ([], 'f8')) + assert_raises(ValueError, np.zeros(1, dtype='i4').view, []) + + assert_equal(np.zeros(2, dtype=[]) == np.zeros(2, dtype=[]), + np.ones(2, dtype=bool)) + + assert_equal(np.zeros((1, 2), dtype=[]) == a, + np.ones((1, 2), dtype=bool)) + class TestSubarray(object): def test_single_subarray(self): |