Repository navigation
ENH: Allow NEP 42 dtypes to use np.save and np.load - #24142
Merged
Merged
Conversation
Member
|
Tests are unhappy. @rkern would you prefer more here? I would be fine with doing this this even if it is not ideal; since I don't think it blocks the right solution and there is that warning anyway. |
Member
|
Yeah, I think it's a fine short-term workaround. The warnings are appreciated. |
Member
Author
Good now, I was unknowingly using a too-new pytest feature. |
seberg
reviewed
Jul 11, 2023
seberg
left a comment
Member
There was a problem hiding this comment.
I think the test/SF reduce implementation can be drastically simplified. The rest looks nice good though, thanks.
Member
|
Thanks Nathan. |
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
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.
Fixes #24110
First, this makes it so that by default NEP 42 dtypes can't be pickled unless the dtype has a pickle implementation. Currently numpy will pickle them, but won't be able to unpickle them because the type code written to disk is invalid. Erroring is an improvement over writing corrupt files, I think.
Second, if a type can be pickled, this makes it so that
np.savewill save the array using pickle and will lie that the dtype is object (see @rkern's suggestion). I've made it so if this happens a UserWarning will get printed. Unfortunately there's no way to indicate in the file that this really isn't an object array, so I can't do much on the load side to detect when this happens. Hopefully theUserWarningat save time is enough? I think adding a way to indicate in the file that we're not really storing an object array would require a revision to thenpyfile format, which ideally I'd like to avoid.Last, added a pickle implementation to the scaled float test dtype and then added a test doing a round-trip save and load with a scale float array.