issues: 557257598
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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 557257598 | MDU6SXNzdWU1NTcyNTc1OTg= | 3731 | Repeated coordinates leads to unintuitive (broken?) indexing behaviour | 8238804 | open | 0 | 13 | 2020-01-30T04:21:57Z | 2023-11-30T08:58:22Z | NONE | MCVE Code Sample```python import xarray as xr import numpy as np sample_idx = xr.IndexVariable("sample_id", ["a", "b", "c"]) da = xr.DataArray(np.eye(3), coords=(sample_idx, sample_idx)) da.shape (3, 3)da[1, :].shape (3, 3)da.loc["a", :].shape (3, 3)da.loc[:, "a"].shape ()da[:, 0].shape ()da[:, 1] <xarray.DataArray ()>array(1.)Coordinates:sample_id <U1 'b'``` Expected OutputI had expected: ```python da.shape (3, 3)da[1, :].shape (3)da.loc["a", :].shape (3)da.loc[:, "a"].shape (3)da[:, 1] <xarray.DataArray (sample_id: 3)>array([0., 1., 0.])Coordinates:sample_id <U1 'a' 'b' 'c'``` Problem DescriptionWhen coordinates are shared between dimensions (as would happen if a pairwise measurement is taken) indexing behaves strangely. It looks like indexing into the initial indices doesn't do anything, while indexing into the last index applies the selection across all dimensions. ```python da3d = xr.DataArray( np.arange(27).reshape((3,3,3)), coords=(sample_idx, sample_idx, sample_idx) ) print(da3d.loc["a"].shape) print(da3d.loc["a", "a"].shape) print(da3d.loc[:, :, "a"].shape) (3, 3, 3)(3, 3, 3)()``` Output of
|
{
"url": "https://api.github.com/repos/pydata/xarray/issues/3731/reactions",
"total_count": 1,
"+1": 1,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} |
13221727 | issue |