idxmax with multiple dimensions#10680
Conversation
|
Looks good @gcaria ! Would it be possible to add a couple tests? |
| res[_dim] = _res | ||
|
|
||
| if len(dims) == 1: | ||
| res = res[dims[0]] |
There was a problem hiding this comment.
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.
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