-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
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 0 However, arguments of <xarray.Dataset>
Dimensions: (points: 3)
Data variables:
x (points) int64 0 1 2
y (points) int64 0 1 0 This 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.4 so 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 --diff
whats-new.rst
for all changes andapi.rst
for 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
OrderedDict
ofDataArray
s.Example:
(Because the returned object is an
OrderedDict
, it is not beautifully printed. The returned type can be axr.Dataset
if we want.)Although in #1388
argmin_indexes()
was originally suggested so that we can pass the result intoisel_point
,current implementation of
isel_points
does NOT work for this case.This is mainly because
isel_points
currently does not work for 0-dimensional or multi-dimensional input.x
as an indexer rather than the coordinate of indexer.For 1, I have prepared modification of
isel_points
to 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_indexes
to return not only the indicated dimension but also all the dimensions, likeor
isel_point
so that it takes care of theindexer
's coordinate ifxr.DataArray
is 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_indexes
to returnxr.Dataset
rather than anOrderedDict
, and also change API ofisel_points
to acceptxr.Dataset
.It keeps backward-compatibility.
Any comments are welcome.