-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
ENH: properly account for trailing padding in PEP3118 #7798
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Fixes #7797
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7023,8 +7023,6 @@ def test_native_padding_2(self): | |
self._check('^x3T{xi}', {'f0': (({'f0': ('i', 1)}, (3,)), 1)}) | ||
|
||
def test_trailing_padding(self): | ||
# Trailing padding should be included, *and*, the item size | ||
# should match the alignment if in aligned mode | ||
align = np.dtype('i').alignment | ||
size = np.dtype('i').itemsize | ||
|
||
|
@@ -7033,18 +7031,31 @@ def aligned(n): | |
|
||
base = dict(formats=['i'], names=['f0']) | ||
|
||
self._check('ix', dict(itemsize=aligned(size + 1), **base)) | ||
self._check('ixx', dict(itemsize=aligned(size + 2), **base)) | ||
self._check('ixxx', dict(itemsize=aligned(size + 3), **base)) | ||
self._check('ixxxx', dict(itemsize=aligned(size + 4), **base)) | ||
self._check('i7x', dict(itemsize=aligned(size + 7), **base)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think these tests might remain valid with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The PEP3118 spec is unclear about this. One could argue the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whereas the |
||
self._check('ix', dict(itemsize=size + 1, **base)) | ||
self._check('ixx', dict(itemsize=size + 2, **base)) | ||
self._check('ixxx', dict(itemsize=size + 3, **base)) | ||
self._check('ixxxx', dict(itemsize=size + 4, **base)) | ||
self._check('i7x', dict(itemsize=size + 7, **base)) | ||
|
||
self._check('T{i:f0:x}', dict(itemsize=aligned(size + 1), **base)) | ||
self._check('T{i:f0:xx}', dict(itemsize=aligned(size + 2), **base)) | ||
self._check('T{i:f0:xxx}', dict(itemsize=aligned(size + 3), **base)) | ||
self._check('T{i:f0:xxxx}', dict(itemsize=aligned(size + 4), **base)) | ||
self._check('T{i:f0:7x}', dict(itemsize=aligned(size + 7), **base)) | ||
|
||
self._check('^ix', dict(itemsize=size + 1, **base)) | ||
self._check('^ixx', dict(itemsize=size + 2, **base)) | ||
self._check('^ixxx', dict(itemsize=size + 3, **base)) | ||
self._check('^ixxxx', dict(itemsize=size + 4, **base)) | ||
self._check('^i7x', dict(itemsize=size + 7, **base)) | ||
|
||
# check we can convert to memoryview and back, aligned and unaligned | ||
arr = np.zeros(3, dtype=np.dtype('u1,i4,u1', align=True)) | ||
assert_equal(arr.dtype, np.array(memoryview(arr)).dtype) | ||
|
||
arr = np.zeros(3, dtype=np.dtype('u1,i4,u1', align=False)) | ||
assert_equal(arr.dtype, np.array(memoryview(arr)).dtype) | ||
|
||
def test_native_padding_3(self): | ||
dt = np.dtype( | ||
[('a', 'b'), ('b', 'i'), | ||
|
@@ -7075,15 +7086,9 @@ def test_intra_padding(self): | |
align = np.dtype('i').alignment | ||
size = np.dtype('i').itemsize | ||
|
||
def aligned(n): | ||
return (align*(1 + (n-1)//align)) | ||
|
||
self._check('(3)T{ix}', (dict( | ||
names=['f0'], | ||
formats=['i'], | ||
offsets=[0], | ||
itemsize=aligned(size + 1) | ||
), (3,))) | ||
expected_dtype = {'names': ['f0'], 'formats': ['i'], | ||
'itemsize': np.dtype('i,V1', align=True).itemsize} | ||
self._check('(3)T{ix}', (expected_dtype, (3,))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this an exact duplicate of the above test? What am I missing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh sorry, I fudged the rebase here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although perhaps using |
||
|
||
def test_char_vs_string(self): | ||
dt = np.dtype('c') | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change of message deliberate, or just a consequence of the merge?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deliberate, based on your review above.
I just did a little bit more than a simple rebase. I also added support for 0-sized unnamed padding, see the release note.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh I see what you mean, the previous message seems good enough.