-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
BUG: Fix misuse of .names and .fields in various places (backport 14290 to 1.17) #14339
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
charris
merged 13 commits into
numpy:maintenance/1.17.x
from
eric-wieser:fix-if-fields-1.17
Aug 23, 2019
Merged
BUG: Fix misuse of .names and .fields in various places (backport 14290 to 1.17) #14339
charris
merged 13 commits into
numpy:maintenance/1.17.x
from
eric-wieser:fix-if-fields-1.17
Aug 23, 2019
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
This replaces some more uses of `bool(dt.fields)` and `bool(dt.names)` with `dt.names is not None`. `dt.fields is not None` would have worked too, but checking `.names` is more prevalent elsewhere
Previously attempting to access a field of such an array (such as when printing it!) would result in `ValueError: Changing the dtype of a 0d array is only supported if the itemsize is unchanged`.
Previously this would fail with `ValueError: could not assign tuple of length 2 to structure with 3 fields.`, now it raises `NotImplementedError`.
Replacing empty tuples with `None` is a bad idea, and just results in an API that is hard to consume - especially since the behavior was never documented. This affects `get_names`, `get_names_flat`, and `get_fieldstructure`.
In these instances the behavior isn't changed, since the for loop below acts like an if. However, in general this is an antipattern that crashes on 0-field structured types, and is warned against in the docs. If we remove instances of the antipattern, it will hopefully not reappear via copy-paste code.
Without this change, `np.dtype('V0')` and `np.dtype([])` produced types with the same name, which was misleading as they are different types. This is mostly cosmetic.
Also adjust the code to more clearly indicate what actually happens. The behavior is identical before and after this patch.
…rrayprint No behavior change here
Previously passing `dtype=[], names=['a']` would append an extra field, even though `dtype=['a'], names=['b', 'c']` does not.
…mtxt This only affects arrays with `dtype([])`, but also follows the recommended way to check for structured arrays in our docs
This check would fail on the structured type `np.dtype([])`. No test, since I don't really understand mrecords
It's not clear that these have any visible effect, but we should be consistent with how we detect structured types.
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.
Backport of gh-14290. All but the merge commit are identical.