Uh oh!
There was an error while loading. Please reload this page.
Argmin indexes - #1469
Conversation
shoyer
commented
Jul 3, 2017
A few quick thoughts on API design:
|
@shoyer
defindexes_min(self, dims=None, skipna=True):and defidxmin(self, dim=None, skipna=True, keep_dims=False):(I found
In [1]: importxarrayasxr
...: 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) float641.44.3In [2]: da.indexes_min(dims='y')
Out[2]: <xarray.Dataset>Dimensions: (x: 3)
Coordinates:
*x (x) <U1'c''b''a'Datavariables:
y (x) float64010However, arguments of <xarray.Dataset>Dimensions: (points: 3)
Datavariables:
x (points) int64012y (points) int64010This behavior is more intuitive? |
shoyer
commented
Jul 5, 2017
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 |
fujiisoup
commented
Jul 5, 2017
@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'Datavariables:
y (x) float641.44.31.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. |
johnomotani
commented
Apr 4, 2020
fujiisoup
commented
Apr 4, 2020
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.