8000 BUG: Make dtype.descr error for out-of-order fields by eric-wieser · Pull Request #10391 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG: Make dtype.descr error for out-of-order fields #10391

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
Jan 14, 2018

Conversation

eric-wieser
Copy link
Member
@eric-wieser eric-wieser commented Jan 12, 2018

cc @ahaldane since #6053 exposes this to user code more often.

Currently returns garbage, Now

>>> data = np.zeros(1, dtype=[('a', int), ('b', float)])
>>> data = data[['b','a']]
>>> data.dtype.descr
ValueError

@eric-wieser
Copy link
Member Author
eric-wieser commented Jan 14, 2018

I think this might make debugging downstream problems with 1.14 easier, so would be inclined to get this into 1.14.1.

Updated with tests

@eric-wieser eric-wieser force-pushed the fix-fields-descr branch 4 times, most recently from ffbb286 to 646279a Compare January 14, 2018 03:22
< 8000 td class="blob-num blob-num-addition empty-cell">
# represent that
y = self.data[['col2', 'col1']]
assert_equal(y.dtype.names, ('col2', 'col1'))
assert_raises(ValueError, lambda: y.dtype.descr)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously returned [('', '|V4'), ('col2', '<i4'), ('col1', '<i4')], which swapped col1 with col3!

@ahaldane
Copy link
Member

Yes, this seems like the right thing to do, no matter what we decide to do about #10387.

@ahaldane
Copy link
Member
ahaldane commented Jan 14, 2018

LGTM. I plan to merge after sleeping on it :)

While I'm here I'll just link to #10389, since it is related. (I was going to suggest mentioning it in the commit message, but this PR doesn't actually fix it.)

@eric-wieser
Copy link
Member Author

I think in both cases, we need a convenient way to request the fields be reordered to something compatible - perhaps via a copy, or just a shuffle of the field order

@ahaldane
Copy link
Member

All right, let's merge this to help root out bugs.

@ahaldane ahaldane merged commit a6705eb into numpy:master Jan 14, 2018
@charris charris changed the title BUG: Instead of returning garbage, make dtype.descr error for out-of-order fields BUG: Make dtype.descr error for out-of-order fields Feb 9, 2018
@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label Feb 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0