8000 Merge pull request #6361 from seberg/issue6359 · numpy/numpy@986a98c · GitHub
[go: up one dir, main page]

Skip to content

Commit 986a98c

Browse files
committed
Merge pull request #6361 from seberg/issue6359
BUG: Add void field at end of dtype.descr to match itemsize
2 parents ea289ee + 89ef119 commit 986a98c

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-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):

numpy/core/tests/test_multiarray.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5424,6 +5424,16 @@ class ArrayLike(object):
54245424
assert_equal(np.array(ArrayLike()), 1)
54255425

54265426

5427+
def test_array_interface_itemsize():
5428+
# See gh-6361
5429+
my_dtype = np.dtype({'names': ['A', 'B'], 'formats': ['f4', 'f4'],
5430+
'offsets': [0, 8], 'itemsize': 16})
5431+
a = np.ones(10, dtype=my_dtype)
5432+
descr_t = np.dtype(a.__array_interface__['descr'])
5433+
typestr_t = np.dtype(a.__array_interface__['typestr'])
5434+
assert_equal(descr_t.itemsize, typestr_t.itemsize)
5435+
5436+
54275437
def test_flat_element_deletion():
54285438
it = np.ones(3).flat
54295439
try:

0 commit comments

Comments
 (0)
0