home / github

Menu
  • Search all tables
  • GraphQL API

issues

Table actions
  • GraphQL API for issues

2 rows where repo = 13221727, state = "open" and user = 5308236 sorted by updated_at descending

✎ View and edit SQL

This data as json, CSV (advanced)

Suggested facets: created_at (date), updated_at (date)

type 1

  • issue 2

state 1

  • open · 2 ✖

repo 1

  • xarray · 2 ✖
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
446868198 MDU6SXNzdWU0NDY4NjgxOTg= 2978 sel(method=x) is not propagated for MultiIndex mschrimpf 5308236 open 0     3 2019-05-21T23:30:56Z 2022-04-09T02:09:00Z   NONE      

When passing a method different from None to the selection method (e.g. .sel(method='nearest')), it is not propagated if the index is a MultiIndex. Specifically, the passing of the method key seems to be missing in xarray/core/indexing.py:convert_label_indexer https://github.com/pydata/xarray/blob/0811141e8f985a1f3b95ead92c3850cc74e160a5/xarray/core/indexing.py#L158-L159

For a normal index, the method is passed properly: https://github.com/pydata/xarray/blob/0811141e8f985a1f3b95ead92c3850cc74e160a5/xarray/core/indexing.py#L181

This leads to an unexpected KeyError when the selection value is not in the index, even if a nearest value could have been found.

Output of xr.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 3.6.7.final.0 python-bits: 64 OS: Linux OS-release: 4.4.0-143-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: en_US.UTF-8 xarray: 0.10.8 pandas: 0.24.2 numpy: 1.16.2 scipy: 1.1.0 netCDF4: 1.4.2 h5netcdf: None h5py: 2.8.0 Nio: None zarr: None bottleneck: None cyordereddict: None dask: 0.20.0 distributed: None matplotlib: 3.0.1 cartopy: None seaborn: 0.9.0 setuptools: 40.8.0 pip: 19.0.3 conda: None pytest: 3.10.0 IPython: 7.1.1 sphinx: None
{
    "url": "https://api.github.com/repos/pydata/xarray/issues/2978/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
    xarray 13221727 issue
376953925 MDU6SXNzdWUzNzY5NTM5MjU= 2537 single coordinate is overwritten with dimension by set_index mschrimpf 5308236 open 0     8 2018-11-02T20:17:54Z 2020-11-02T17:24:35Z   NONE      

Code Sample

python import xarray as xr d = xr.DataArray([0], coords={'coord': ('dim', [0])}, dims=['dim']) d.set_index(append=True, inplace=True, dim=['coord']) d.sel(dim=0) # works d.sel(coord=0) # doesn't work, coord does not exist anymore print(d)

<xarray.DataArray (dim: 1)> array([0]) Coordinates: * dim (dim) int64 0

Problem description

when a DataArray is initialized with a dimension containing only one coordinate, selection on the coordinate is not directly possible. As a workaround, we can set_index but if there is only one coordinate on a dimension, the coordinate vanishes and its values are attached to the dimension directly.

The DataArrays in my use case are generic, in some cases there are multiple coordinates and sometimes there is only one. If the one consistent coordinate is discarded for some cases, follow-up code becomes tedious. Having a single-coordinate MultiIndex would be much more intuitive so that one can still .sel over the coordinate.

Expected Output

<xarray.DataArray (dim: 1)> array([0]) Coordinates: * dim MultiIndex coord (dim) int64 0

For more than one coordinate on the dimension, the dimension becomes a MultiIndex with all the coordinates. With only a single coordinate however, this does not happen.

Output of xr.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 3.6.6.final.0 python-bits: 64 OS: Linux OS-release: 4.4.0-137-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: en_US.UTF-8 xarray: 0.10.8 pandas: 0.23.4 numpy: 1.15.1 scipy: 1.1.0 netCDF4: 1.4.1 h5netcdf: None h5py: 2.8.0 Nio: None zarr: None bottleneck: None cyordereddict: None dask: 0.19.1 distributed: None matplotlib: 2.2.3 cartopy: None seaborn: 0.9.0 setuptools: 39.1.0 pip: 10.0.1 conda: None pytest: 3.8.0 IPython: 6.5.0 sphinx: None
{
    "url": "https://api.github.com/repos/pydata/xarray/issues/2537/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
    xarray 13221727 issue

Advanced export

JSON shape: default, array, newline-delimited, object

CSV options:

CREATE TABLE [issues] (
   [id] INTEGER PRIMARY KEY,
   [node_id] TEXT,
   [number] INTEGER,
   [title] TEXT,
   [user] INTEGER REFERENCES [users]([id]),
   [state] TEXT,
   [locked] INTEGER,
   [assignee] INTEGER REFERENCES [users]([id]),
   [milestone] INTEGER REFERENCES [milestones]([id]),
   [comments] INTEGER,
   [created_at] TEXT,
   [updated_at] TEXT,
   [closed_at] TEXT,
   [author_association] TEXT,
   [active_lock_reason] TEXT,
   [draft] INTEGER,
   [pull_request] TEXT,
   [body] TEXT,
   [reactions] TEXT,
   [performed_via_github_app] TEXT,
   [state_reason] TEXT,
   [repo] INTEGER REFERENCES [repos]([id]),
   [type] TEXT
);
CREATE INDEX [idx_issues_repo]
    ON [issues] ([repo]);
CREATE INDEX [idx_issues_milestone]
    ON [issues] ([milestone]);
CREATE INDEX [idx_issues_assignee]
    ON [issues] ([assignee]);
CREATE INDEX [idx_issues_user]
    ON [issues] ([user]);
Powered by Datasette · Queries took 77.157ms · About: xarray-datasette