html_url,issue_url,id,node_id,user,created_at,updated_at,author_association,body,reactions,performed_via_github_app,issue
https://github.com/pydata/xarray/issues/3432#issuecomment-919981497,https://api.github.com/repos/pydata/xarray/issues/3432,919981497,IC_kwDOAMm_X8421c25,4160723,2021-09-15T12:38:29Z,2021-09-15T12:38:29Z,MEMBER,"@Hoeze this is now implemented in #5692 (`stack` is not yet refactored so I reproduced your example in a slightly different way):
```python
>>> stacked.isel(observations=1)
Dimensions: (genes: 2)
Coordinates:
* genes (genes) >> df = stacked.test.to_pandas()
>>> df
individuals c d
subtissues e f e f
genes
a 1 2 3 4
b 1 2 3 4
>>> df.iloc[:, 1]
genes
a 2
b 2
Name: (c, f), dtype: int64
```
I'm not sure if we should write an ad-hoc object in xarray for scalar multiindices.
The alternative is to think of a more systematic solution in pandas, which likely implies creating an ad-hoc subclass of tuple which is basically a pickle-able namedtuple.
It must be a subclass of tuple otherwise it will break things for a lot of people around the world (the userbase of pandas is MUCH larger than xarray's). And it must be serializable for obvious reasons.
In both cases, the size of this change is very large.
The third and significantly easier option is that, on sel/isel, xarray should automatically unstack any scalar slices of a multiindex. Meaning that the 'observations' coord would simply disappear, leaving only 'individuals' and 'subtissues'.
However, It would carry the problem that, if one cuts a scalar slice and a vector slice from the dimension, he won't be able to concatenate them back together.
@shoyer what's your opinion?
","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,510844652
https://github.com/pydata/xarray/issues/3432#issuecomment-545134181,https://api.github.com/repos/pydata/xarray/issues/3432,545134181,MDEyOklzc3VlQ29tbWVudDU0NTEzNDE4MQ==,1200058,2019-10-22T20:14:38Z,2019-10-22T20:17:26Z,NONE,"@max-sixty here you go:
```python3
import xarray as xr
print(xr.__version__)
ds = xr.Dataset({
""test"": xr.DataArray(
[[[1,2],[3,4]], [[1,2],[3,4]]],
dims=(""genes"", ""individuals"", ""subtissues""),
coords={
""genes"": [""a"", ""b""],
""individuals"": [""c"", ""d""],
""subtissues"": [""e"", ""f""],
}
)
})
print(ds)
stacked = ds.stack(observations=[""individuals"", ""subtissues""])
print(stacked)
print(stacked.isel(observations=1))
```
result:
```
Dimensions: (genes: 2)
Coordinates:
* genes (genes)