-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Argmin indexes #1469
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
Argmin indexes #1469
Conversation
|
A few quick thoughts on API design:
|
|
@shoyer
def indexes_min(self, dims=None, skipna=True):and def idxmin(self, dim=None, skipna=True, keep_dims=False):(I found
In [1]: import xarray as xr
...: da = xr.DataArray([[1, 2], [51, 40], [5, 6]],
...: [('x', ['c', 'b', 'a']), ('y', [1.4, 4.3])])
...: da
...:
Out[1]:
<xarray.DataArray (x: 3, y: 2)>
array([[ 1, 2],
[51, 40],
[ 5, 6]])
Coordinates:
* x (x) <U1 'c' 'b' 'a'
* y (y) float64 1.4 4.3
In [2]: da.indexes_min(dims='y')
Out[2]:
<xarray.Dataset>
Dimensions: (x: 3)
Coordinates:
* x (x) <U1 'c' 'b' 'a'
Data variables:
y (x) float64 0 1 0However, arguments of <xarray.Dataset>
Dimensions: (points: 3)
Data variables:
x (points) int64 0 1 2
y (points) int64 0 1 0This behavior is more intuitive? |
|
OK, I think I finally understand the nuance of the return value -- thanks for describing that fully for me. In theory (after #974 is implemented), the current return value from So maybe that is the right choice, though I'm not entirely certain yet. Side note: I'm still not super happy with the names |
|
@shoyer I think my current implementation does not work even for (the future version of) As you suggested, it looks more <xarray.Dataset>
Dimensions: (x: 3)
Coordinates:
* x (x) <U1 'c' 'b' 'a'
Data variables:
y (x) float64 1.4 4.3 1.4so that it can be passed to This API looks much more natural to me than the current one, although it has to wait for #974. For the function name. |
|
Hi @johnomotani . |
git diff master | flake8 --diffwhats-new.rstfor all changes andapi.rstfor new APIWith this PR, ValueError raises if
argmin()is called by a multi-dimensional array.argmin_indexes()method is also added forxr.DataArray.Current API design for
argmin_indexes()returnsthe argmin-indexes as an
OrderedDictofDataArrays.Example:
(Because the returned object is an
OrderedDict, it is not beautifully printed. The returned type can be axr.Datasetif we want.)Although in #1388
argmin_indexes()was originally suggested so that we can pass the result intoisel_point,current implementation of
isel_pointsdoes NOT work for this case.This is mainly because
isel_pointscurrently does not work for 0-dimensional or multi-dimensional input.xas an indexer rather than the coordinate of indexer.For 1, I have prepared modification of
isel_pointsto accept multi-dimensional arrays, but I guess it should be in another PR after the API decision.(It is related in #475, and #974.)
For 2, we should either
argmin_indexesto return not only the indicated dimension but also all the dimensions, likeor
isel_pointso that it takes care of theindexer's coordinate ifxr.DataArrayis passed for asindexers.I originally worked with the second option for the modification of
isel_points,the second option breaks the backward-comaptibility and is somehow magical.
Another alternertive is to
argmin_indexesto returnxr.Datasetrather than anOrderedDict, and also change API ofisel_pointsto acceptxr.Dataset.It keeps backward-compatibility.
Any comments are welcome.