Handle scalar coercion with more nuance#76
Merged
Merged
Conversation
f62565a handled reading length-1 datasets as scalars (since numpy 2 no longer handled these cases automatically. However, it was a little overzealous and always converted numpy scalar objects (np.generic) into python scalar objects. Two examples where this was a problem were NXData data_scale_factor and data_offset; these used to return a numpy scalar and now returned the inner value (also, the typing for these was _completely wrong_). This fixes those annotations, and returns the numpy scalar - if appropriate - because these fields can also validly contain arrays. Also, slightly tightened up conversion cases in other instances of e.g. str conversion.
0253387 to
d447416
Compare
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.
f62565a handled reading length-1 datasets as scalars (since numpy 2 no longer handled these cases automatically. However, it was a little overzealous and always converted numpy scalar objects (np.generic) into python scalar objects.
Two examples where this was a problem were NXData data_scale_factor and data_offset; these used to return a numpy scalar and now returned the inner value (also, the typing for these was completely wrong).
This fixes those annotations, and returns the numpy scalar - if appropriate - because these fields can also validly contain arrays.
Also, slightly tightened up conversion cases in other instances of e.g. str conversion.