Repository navigation
allow using __array_function__ as a fallback for missing Array API functions - #9530
Conversation
We don't do this anywhere elsewhere, so it doesn't make sense to do this only for `nanprod`.
|
This seems good, but does it cover this comment? #8834 (comment) |
|
Thanks @keewis - this would be very helpful! |
I don't think it does, but I think array types that implement both |
|
This almost certainly breaks vectorized indexing with cupy if you don't implement the fallback Though how are the pint tests passing? Do we have indexing tests with pint? |
As far as I can tell, That said, we should definitely try to provide an implementation for |
|
OK yes, lot less urgent then. I thought they had all implemented |
|
|
| return NdArrayLikeIndexingAdapter(array) | ||
| if hasattr(array, "__array_namespace__"): | ||
| return ArrayApiIndexingAdapter(array) | ||
| if hasattr(array, "__array_function__"): |
There was a problem hiding this comment.
I'm confused now, why does the indexing adapter affect what's used for reductions?
There was a problem hiding this comment.
I don't think that's the case. What I mentioned in the meeting was that we could use __array_function__ as a fallback for nan* reductions, whereas choosing the wrong indexing adapter will cause xarray to try indexing with a method the array type might not support.
I guess this is kinda hard to figure out implicitly, and I'd love to have a way (a special attribute like __xarray_preferred_array_protocol__?) to explicitly communicate which protocol is preferred. That way, we won't have to worry about cupy and pint implementing the Array API, and cubed can just set that attribute to state that it considers __array_function__ a fallback and instead prefers to use __array_namespace__ indexing.
There was a problem hiding this comment.
array_function as a fallback for nan* reductions,
👍 sorry I got confused.
As discussed in #8834 (comment), this swaps the order of special casing for types implementing both
__array_function__and__array_namespace__, such that the Array API is preferred over__array_function__.I've also disabled passing the
outkwarg tonanprod, as that was the only occurrence where we actually do that, all othernan*functions silently ignore that kwarg.whats-new.rstcc @tomwhite