Skip to content

Handle scalar coercion with more nuance#76

Merged
ndevenish merged 1 commit into
mainfrom
nuanced_scalar
Mar 25, 2026
Merged

Handle scalar coercion with more nuance#76
ndevenish merged 1 commit into
mainfrom
nuanced_scalar

Conversation

@ndevenish
Copy link
Copy Markdown
Member

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.

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.
@ndevenish ndevenish merged commit 17fa711 into main Mar 25, 2026
6 checks passed
@ndevenish ndevenish deleted the nuanced_scalar branch March 25, 2026 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant