diff options
author | ahaldane <ealloc@gmail.com> | 2015-09-27 19:26:35 -0400 |
---|---|---|
committer | ahaldane <ealloc@gmail.com> | 2015-09-27 19:26:35 -0400 |
commit | 986a98c8020f90ae95dd65817a2dcc5e5f336172 (patch) | |
tree | 9292a574ecd76e559cc787a6335a3ca2c44ffc34 /numpy/core | |
parent | ea289ee45dffa85d2fde07685eb3334816d8af7c (diff) | |
parent | 89ef1193448297d76951f52efb68436be218fb7d (diff) | |
download | numpy-986a98c8020f90ae95dd65817a2dcc5e5f336172.tar.gz |
Merge pull request #6361 from seberg/issue6359
BUG: Add void field at end of dtype.descr to match itemsize
Diffstat (limited to 'numpy/core')
-rw-r--r-- | numpy/core/_internal.py | 4 | ||||
-rw-r--r-- | numpy/core/tests/test_dtype.py | 15 | ||||
-rw-r--r-- | numpy/core/tests/test_multiarray.py | 10 |
3 files changed, 28 insertions, 1 deletions
diff --git a/numpy/core/_internal.py b/numpy/core/_internal.py index 879f4a224..81f5be4ad 100644 --- a/numpy/core/_internal.py +++ b/numpy/core/_internal.py @@ -121,6 +121,10 @@ def _array_descr(descriptor): offset += field[0].itemsize result.append(tup) + if descriptor.itemsize > offset: + num = descriptor.itemsize - offset + result.append(('', '|V%d' % num)) + return result # Build a new array from the information in a pickle. diff --git a/numpy/core/tests/test_dtype.py b/numpy/core/tests/test_dtype.py index 496664622..29f2ee7bd 100644 --- a/numpy/core/tests/test_dtype.py +++ b/numpy/core/tests/test_dtype.py @@ -535,7 +535,7 @@ class TestString(TestCase): # Pull request #4722 np.array(["", ""]).astype(object) -class TestDtypeAttributeDeletion(object): +class TestDtypeAttributeDeletion(TestCase): def test_dtype_non_writable_attributes_deletion(self): dt = np.dtype(np.double) @@ -552,6 +552,19 @@ class TestDtypeAttributeDeletion(object): for s in attr: assert_raises(AttributeError, delattr, dt, s) + +class TestDtypeAttributes(TestCase): + def test_descr_has_trailing_void(self): + # see gh-6359 + dtype = np.dtype({ + 'names': ['A', 'B'], + 'formats': ['f4', 'f4'], + 'offsets': [0, 8], + 'itemsize': 16}) + new_dtype = np.dtype(dtype.descr) + assert_equal(new_dtype.itemsize, 16) + + class TestDtypeAttributes(TestCase): def test_name_builtin(self): diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py index 57cc745a6..872f9bde4 100644 --- a/numpy/core/tests/test_multiarray.py +++ b/numpy/core/tests/test_multiarray.py @@ -5424,6 +5424,16 @@ def test_array_interface(): assert_equal(np.array(ArrayLike()), 1) +def test_array_interface_itemsize(): + # See gh-6361 + my_dtype = np.dtype({'names': ['A', 'B'], 'formats': ['f4', 'f4'], + 'offsets': [0, 8], 'itemsize': 16}) + a = np.ones(10, dtype=my_dtype) + descr_t = np.dtype(a.__array_interface__['descr']) + typestr_t = np.dtype(a.__array_interface__['typestr']) + assert_equal(descr_t.itemsize, typestr_t.itemsize) + + def test_flat_element_deletion(): it = np.ones(3).flat try: |