-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
BUG: fixed dtype alignment for array of structs in case of converting from tuple descr #10923
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
Conversation
if (!PyArray_DescrConverter(PyTuple_GET_ITEM(obj,0), &type)) { | ||
return NULL; | ||
} | ||
if (align) { |
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.
all the tab characters here should be four spaces. (no tabs allowed in numpy code!)
(same below)
Looks good, thanks for the PR! I have two requests, and after that I think it will be ready to merge:
|
Done. |
numpy/core/tests/test_dtype.py
Outdated
@@ -205,6 +205,10 @@ def test_aligned_size(self): | |||
assert_equal(dt3.itemsize, 11) | |||
assert_equal(dt1, dt2) | |||
assert_equal(dt2, dt3) | |||
# Array of subtype should preserve alignment | |||
dt1 = np.dtype([('a', '|i1'), ('b', [('f0', '<i2'), ('f1', '<f4')], 2)], align=True) | |||
assert_equal(dt1.descr, [('a', '|i1'), ('', '|V3'), ('b', [('f0', '<i2'), ('', '|V2'), ('f1', '<f4')], (2,))]) |
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.
these lines go over 80 characters, which is the max we want. Could you split them so they are less than 80 chars? Something like
assert_equal(dt1.descr, [('a', '|i1'), ('', '|V3'),
('b', [('f0', '<i2'), ('', '|V2'),
('f1', '<f4')], (2,))])
Everything else looks good. |
…f converting from tuple descr
Fixed lines length. |
Great, thanks a lot @ihormelnyk ! This was a pretty annoying bug, I'm glad it's fixed. Merging now... |
Descr of array of subtype with alignment
t = np.dtype([('a', '|i1'), ('b', [('f0', '<i2'), ('f1', '<f4')], 2)], align=True)
actual dtype:
[('a', '|i1'), ('b', [('f0', '<i2'), ('f1', '<f4')], (2,))]
expected dtype:
[('a', '|i1'), (, '|V3'), ('b', [('f0', '<i2'), (, '|V2'), ('f1', '<f4')], 2)]
Fixes #663.