10000 BUG: Add void field at end of dtype.descr to match itemsize · jaimefrio/numpy@f52359b · GitHub
[go: up one dir, main page]

Skip to content

Commit f52359b

Browse files
sebergjaimefrio
authored andcommitted
BUG: Add void field at end of dtype.descr to match itemsize
dtype.descr returns void fields to explain the padding part of the dtype. The last void field for the itemsize itself was however not included. Closes numpygh-6359
1 parent 836c771 commit f52359b

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

numpy/core/_internal.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ def _array_descr(descriptor):
121121
offset += field[0].itemsize
122122
result.append(tup)
123123

124+
if descriptor.itemsize > offset:
125+
num = descriptor.itemsize - offset
126+
result.append(('', '|V%d' % num))
127+
124128
return result
125129

126130
# Build a new array from the information in a pickle.

numpy/core/tests/test_dtype.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ def test_empty_string_to_object(self):
535535
# Pull request #4722
536536
np.array(["", ""]).astype(object)
537537

538-
class TestDtypeAttributeDeletion(object):
538+
class TestDtypeAttributeDeletion(TestCase):
539539

540540
def test_dtype_non_writable_attributes_deletion(self):
541541
dt = np.dtype(np.double)
@@ -552,6 +552,19 @@ def test_dtype_writable_attributes_deletion(self):
552552
for s in attr:
553553
assert_raises(AttributeError, delattr, dt, s)
554554

555+
556+
class TestDtypeAttributes(TestCase):
557+
def test_descr_has_trailing_void(self):
558+
# see gh-6359
559+
dtype = np.dtype({
560+
'names': ['A', 'B'],
561+
'formats': ['f4', 'f4'],
562+
'offsets': [0, 8],
563+
'itemsize': 16})
564+
new_dtype = np.dtype(dtype.descr)
565+
assert_equal(new_dtype.itemsize, 16)
566+
567+
555568
class TestDtypeAttributes(TestCase):
556569

557570
def test_name_builtin(self):

0 commit comments

Comments
 (0)
0