home / github / issues

Menu
  • GraphQL API
  • Search all tables

issues: 239918314

This data as json

id node_id number title user state locked assignee milestone comments created_at updated_at closed_at author_association active_lock_reason draft pull_request body reactions performed_via_github_app state_reason repo type
239918314 MDExOlB1bGxSZXF1ZXN0MTI4NDcxOTk4 1469 Argmin indexes 6815844 closed 0     6 2017-07-01T01:23:31Z 2020-06-29T19:36:25Z 2020-06-29T19:36:25Z MEMBER   0 pydata/xarray/pulls/1469
  • [x] Closes #1388
  • [x] Tests added / passed
  • [x] Passes git diff master | flake8 --diff
  • [x] Fully documented, including whats-new.rst for all changes and api.rst for new API

With this PR, ValueError raises if argmin() is called by a multi-dimensional array.

argmin_indexes() method is also added for xr.DataArray. Current API design for argmin_indexes() returns the argmin-indexes as an OrderedDict of DataArrays.

Example: ```python

In [1]: import xarray as xr ...: da = xr.DataArray([[1, 2], [-1, 40], [5, 6]], ...: [('x', ['c', 'b', 'a']), ('y', [1, 0])]) ...: ...: da.argmin_indexes() ...: Out[1]: OrderedDict([('x', <xarray.DataArray 'x' ()> array(1)), ('y', <xarray.DataArray 'y' ()> array(0))])

In [2]: da.argmin_indexes(dims='y') Out[2]: OrderedDict([('y', <xarray.DataArray 'y' (x: 3)> array([0, 0, 0]) Coordinates: * x (x) <U1 'c' 'b' 'a')])

```

(Because the returned object is an OrderedDict, it is not beautifully printed. The returned type can be a xr.Dataset if we want.)

Although in #1388 argmin_indexes() was originally suggested so that we can pass the result into isel_point,

python da.isel_points(**da.argmin_indexes()) current implementation of isel_points does NOT work for this case.

This is mainly because 1. isel_points currently does not work for 0-dimensional or multi-dimensional input. 2. Even for 1-dimensional input (the second one in the above examples), we should also pass 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 + change API of argmin_indexes to return not only the indicated dimension but also all the dimensions, like

```python In [2]: da.argmin_indexes(dims='y') Out[2]: OrderedDict([('y', array([0, 0, 0]), 'x', array(['c' 'b' 'a']))

`` or + change API ofisel_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 + change API of argmin_indexes to return xr.Dataset rather than an OrderedDict, and also change API of isel_points to accept xr.Dataset.
It keeps backward-compatibility.

Any comments are welcome.

{
    "url": "https://api.github.com/repos/pydata/xarray/issues/1469/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
    13221727 pull

Links from other tables

  • 1 row from issues_id in issues_labels
  • 6 rows from issue in issue_comments
Powered by Datasette · Queries took 0.511ms · About: xarray-datasette