-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
ENH: stats.tmean
: add array API support
#20965
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
Conversation
stats.tmean
: add array API support
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.
Minor request then I think this will be in good shape
Does this also close #20959 since this works?
|
I think that issue needs a little more discussion if we are going to make the default |
But I assume there is no reason why we can't merge as is and leave the issue open to discuss changing the default? |
Right. That was my intent. Also, this PR is already a bit unwieldy, so I didn't want to also change the hundreds of existing uses of these functions so the one used by Consider showing support for numpy/numpy#24897. I would by happy to work toward returning 0d arrays consistently if NumPy did. |
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 @mdhaber
# `result_type` should/will handle mixed array/Python scalars | ||
# (data-apis/array-api#805) but doesn't yet. So in the meantime, this fails | ||
# for array-api-strict. | ||
dtype = xp.result_type(temp1.dtype, fillvalue) |
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.
Reference issue
Toward gh-20544
What does this implement/fix?
Adds array API support to
tmean
and paves the way for adding support to other trimmed statistics.Along the way, I discovered that
_lazywhere
not always preservingdtype
was one of several reasons thattmean
wasn't preserving type, so I fixed that. I added associated tests to_lazywhere
, which also led to me making the scalar check inxp_assert
tests optional, since_lazywhere
is (presumably) supposed to return 0-D arrays instead of scalars to follow the example ofwhere
.Additional information
The diff would be smaller with this function if we were to just replace the use of
nanmean
withxp_mean
withnan_policy='omit'
, but that wouldn't help us with any of the other functions. Might as well keep the approach consistent unless we also want to add anxp_var
,xp_max
,xp_min
, etc...Looks like the failure is just gh-20963.