home / github / issues

Menu
  • Search all tables
  • GraphQL API

issues: 476103888

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
476103888 MDU6SXNzdWU0NzYxMDM4ODg= 3176 DataArray.set_index throws error on documented input 2818208 closed 0     7 2019-08-02T10:09:04Z 2019-08-19T16:02:53Z 2019-08-19T16:02:53Z CONTRIBUTOR      

Problem Description

Docs for DataArray.set_index describe the main indexes argument as:

Mapping from names matching dimensions and values given by (lists of) the names of existing coordinates or variables to set as new (multi-)index.

This suggests that one can set a DataArray instance's coordinates by passing in a dimension and a list-like object of coordinates.

MCVE

```python In [1]: import numpy as np

In [2]: import xarray as xr

In [3]: arr = xr.DataArray(data=np.ones((2, 3)), dims=['x', 'y'])

In [4]: arr.dims Out[4]: ('x', 'y')

In [5]: arr.set_index({'x': range(2)}) KeyError
... 144 for n in var_names: --> 145 var = variables[n] 146 if (current_index_variable is not None and 147 var.dims != current_index_variable.dims):

KeyError: 0 ```

At first, I thought it might be because coords and _coords were not being set in this case:

```python In [18]: arr.coords Out[18]: Coordinates: empty

In [19]: arr._coords Out[19]: OrderedDict() ```

but even if I set the coordinates first and then try to re-index, it fails:

python In [20]: arr = xr.DataArray(data=np.ones((2, 3)), dims=['x', 'y'], coords={'x': range(2), 'y': range(3)}) In [21]: arr.set_index({'x': ['a', 'b', 'c']}) ... 144 for n in var_names: --> 145 var = variables[n] 146 if (current_index_variable is not None and 147 var.dims != current_index_variable.dims):

Expected Output

I expect my MCVE to work based on the documentation.

Problem Solution

My guess is that the issue is Xarray is using the merge_indexes function (see here) from the Dataset module, and there is no concept of a variable in a DataArray.

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

Links from other tables

  • 0 rows from issues_id in issues_labels
  • 7 rows from issue in issue_comments
Powered by Datasette · Queries took 0.634ms · About: xarray-datasette