-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
BUG: Further fixes to record and recarray getitem/getattr #5921
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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
embray
added a commit
to embray/astropy
that referenced
this pull request
May 27, 2015
…commit message) numpy-dev. Some of the tests are also fixed by numpy/numpy#5921 it doesn't get merged before Numpy 1.10 is out a workaround will have to be developed.
@embray Could you fix up the commit messages and maybe squash some? Summaries like "Further fixes to record and recarray getitem/getattr" are a bit short on specificity. |
OK. |
c14a4c4
to
f2af07d
Compare
Rebased on the squashed version of #5920. |
Travis build failed at
so unrelated. |
This is a followup to PR numpy#5505, which didn't go quite far enough. This fixes two issues in particular: 1) The record class also needs an updated `__getitem__` that works analogously to its `__getattribute__` so that a nested record is returned as a `record` object and not a plain `np.void`. In other words the old behavior is: ```python >>> rec = np.rec.array([('abc ', (1,1), 1), ('abc', (2,3), 1)], ... dtype=[('foo', 'S4'), ('bar', [('A', int), ('B', int)]), ('baz', int)]) >>> rec[0].bar (1, 1) >>> type(rec[0].bar) <class 'numpy.record'> >>> type(rec[0]['bar']) <type 'numpy.void'> ``` demonstrated inconsistency between `.bar` and `['bar']` on the record object. The new behavior is: ```python >>> type(rec[0]['bar']) <class 'numpy.record'> ``` 2) The second issue is more subtle. The fix to numpy#5505 used the `obj.dtype.descr` attribute to create a new dtype of type `record`. However, this does not recreate the correct type if the fields are not aligned. To demonstrate: ```python >>> dt = np.dtype({'C': ('S5', 0), 'D': ('S5', 6)}) >>> dt.fields dict_proxy({'C': (dtype('S5'), 0), 'D': (dtype('S5'), 6)}) >>> dt.descr [('C', '|S5'), ('', '|V1'), ('D', '|S5')] >>> new_dt = np.dtype((np.record, dt.descr)) >>> new_dt dtype((numpy.record, [('C', 'S5'), ('f1', 'V1'), ('D', 'S5')])) >>> new_dt.fields dict_proxy({'f1': (dtype('V1'), 5), 'C': (dtype('S5'), 0), 'D': (dtype('S5'), 6)}) ``` Using the `fields` dict to construct the new type reconstructs the correct type with the correct offsets: ```python >>> new_dt2 = np.dtype((np.record, dt.fields)) >>> new_dt2.fields dict_proxy({'C': (dtype('S5'), 0), 'D': (dtype('S5'), 6)}) ``` (Note: This is based on numpy#5920 for convenience, but I could decouple the changes if that's preferable.)
f2af07d
to
776c3c3
Compare
Rebased on master, which now includes #5920 |
charris
added a commit
that referenced
this pull request
Jun 2, 2015
BUG: Further fixes to record and recarray getitem/getattr
Thanks @embray. |
dhomeier
pushed a commit
to dhomeier/astropy
that referenced
this pull request
Aug 11, 2015
…commit message) numpy-dev. Some of the tests are also fixed by numpy/numpy#5921 it doesn't get merged before Numpy 1.10 is out a workaround will have to be developed.
embray
added a commit
to embray/PyFITS
that referenced
this pull request
Jan 19, 2016
…commit message) numpy-dev. Some of the tests are also fixed by numpy/numpy#5921 it doesn't get merged before Numpy 1.10 is out a workaround will have to be developed.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a followup to PR #5505, which didn't go quite far
enough. This fixes two issues in particular:
__getitem__
that works analogously to its__getattribute__
so that a nested record is returned as arecord
object and not a plainnp.void
. In other words the old behavior is:demonstrated inconsistency between
.bar
and['bar']
on the record object. The new behavior is:obj.dtype.descr
attribute to create a new dtype of typerecord
. However, this does not recreate the correct type if the fields are not aligned. To demonstrate:Using the
fields
dict to construct the new type reconstructs the correct type with the correct offsets:(Note: This is based on #5920 for convenience, but I could decouple the changes if that's preferable.)