-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
idxmax with multiple dimensions #10680
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
base: main
Are you sure you want to change the base?
Conversation
Looks good @gcaria ! Would it be possible to add a couple tests? |
xarray/computation/computation.py
Outdated
|
||
if len(dims) == 1: | ||
res = res[dims[0]] |
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.
we should have some type stability here so
idmax(dim) -> array
; idxmax((dim,)) -> tuple[array]
; idxmax((dim0, dim1, ...)) -> tuple[array, ...]
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.
I have changed the code to match the behavior of DataArray.arg*
which returns a dict for both idx*((dim,))
and idx*((dim0, dim1, ...))
Does that seem sensible?
Currently navigating the existing tests for arg* and multiple dims
While playing with the tests for arrays that contain nans, I found this, which doesn't seem to make sense (running on main): import xarray as xr
import numpy as np
x = np.array([[ 2., 1., 2., 0., -2., -4., 2.],
[-4., np.nan, 2., np.nan, -2., -4., 2.],
[np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan]])
ar = xr.DataArray(x,
dims=["y", "x"],
coords={
"x": np.arange(x.shape[1]) * 4,
"y": 1 - np.arange(x.shape[0])
},)
ar.idxmin('x', skipna=False) # ---> array([20, 4, 0]) Shouldn't the result be Interestingly |
whats-new.rst