-
-
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
Add small test exposing issue from #7794 and suggestion for _wrap_numpy_scalars
fix
#8821
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for digging into this @huard and @aulemahal. This looks reasonable to me based on the NumPy documentation you referenced, though I probably defer to others on whether there are any subtleties we need to worry about.
Is the inclusion of the hasattr(array, "dtype")
condition to avoid casting zero-dimensional non-NumPy array types to NumPy arrays?
It was rather to avoid casting 0-dimensional non-scalar numpy objects. >>> a = np.array("abc")
>>> np.isscalar(a)
False
>>> np.ndim(a)
0 |
Hi there, I have a library that could benefit from this fix, any updates here? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the ping, @dcherian, and apologies for saying I would look into this and then promptly forgetting about it. I believe it was good to wait until after numpy=2.1
, though, since that appears to have broken is_duck_array
.
Co-authored-by: Justus Magin <[email protected]>
@keewis I applied your suggestion and it seems the issue is fixed! Failures in the tests do not seem related to this PR, I see that the |
_wrap_numpy_scalars
relies onnp.isscalar
, which incorrectly labels a single cftime object as not a scalar.The PR adds logic to handle non-numpy objects using the
np.ndim
function. The logic for built-ins and numpy objects should remain the same.The function logic could possibly be rewritten more clearly as
whats-new.rst
api.rst