8000 BUG: fixed dtype alignment for array of structs in case of converting from tuple descr by ihormelnyk · Pull Request #10923 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

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

Merged
merged 1 commit into from
Apr 18, 2018

Conversation

ihormelnyk
Copy link
@ihormelnyk ihormelnyk commented Apr 17, 2018

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.

if (!PyArray_DescrConverter(PyTuple_GET_ITEM(obj,0), &type)) {
return NULL;
}
if (align) {
Copy link
Member
@ahaldane ahaldane Apr 18, 2018

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)

@ahaldane
Copy link
Member
ahaldane commented Apr 18, 2018

Looks good, thanks for the PR!

I have two requests, and after that I think it will be ready to merge:

  1. In the commit message body, put the exact words "Fixes Alignment doesn't work for array of structs (Trac #2211) #663". This helps us keep track, and also auto-closes the issue on github after merging.

  2. Add a unit test. This should go in the file numpy/core/tests/test_dtype.py, and you can choose an appropriate place inside. For instance, you could add a new function somewhere like the other ones there, for instance right after test_aligned_size. Or, perhaps you should just add some code at the end of test_aligned_size. Either way, I think you just need to add a few lines like in your comment above, using assert_equal to check you get the expected value.

@ihormelnyk
Copy link
Author

Done.

@ihormelnyk ihormelnyk changed the title BUG: fixed dtype alignment for array of structs in case of converting from tuple descr Fixes #663: fixed dtype alignment for array of structs in case of converting from tuple descr Apr 18, 2018
@@ -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,))])
Copy link
Member
@ahaldane ahaldane Apr 18, 2018

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,))])

@ahaldane
Copy link
Member

Everything else looks good.

@ihormelnyk
Copy link
Author

Fixed lines length.

@ahaldane
Copy link
Member

Great, thanks a lot @ihormelnyk !

This was a pretty annoying bug, I'm glad it's fixed. Merging now...

@ahaldane ahaldane merged commit 8be088a into numpy:master Apr 18, 2018
@charris charris changed the title Fixes #663: fixed dtype alignment for array of structs in case of converting from tuple descr BUG: fixed dtype alignment for array of structs in case of converting from tuple descr Jun 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0