-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Variable
may contain numpy scalars with numpy>=2.1
#9399
Comments
Aren't there non-numeric scalars? Perhaps |
I think we should probably add a special case for NumPy scalars, to cast them to arrays. It's simpler for Xarray users to always have NumPy arrays. |
Wouldn't not isinstance(data, (np.generic, np.ndarray)) work then? With that scalars would be passed through to the |
Yes, that would do the trick. |
What is your issue?
I'm not sure if this is a bad thing or not, but while writing tests @TomNicholas and I noticed that starting with
numpy=2.1
,Variable
objects may contain numpy scalars, especially as the result of an aggregation likemean
.This is caused by numpy scalars gaining a
__array_namespace__
method, which is then interpreted byas_compatible_data
as an actual array.To fix this, we could change
xarray/xarray/core/variable.py
Lines 313 to 315 in a04d857
but not sure if that's worth it.
To reproduce, try this in an environment with
numpy>=2.1
:The text was updated successfully, but these errors were encountered: