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/1408#issuecomment-919974416,https://api.github.com/repos/pydata/xarray/issues/1408,919974416,IC_kwDOAMm_X8421bIQ,4160723,2021-09-15T12:27:34Z,2021-09-15T12:27:34Z,MEMBER,"@fujiisoup the behavior that you expect has been implemented in #5692 (I still need to fix/update the tests): ```python >>> ds.sel(x=2) Dimensions: (y: 2) Coordinates: * y (y) >> ds.isel(yx=0) Dimensions: () Coordinates: yx object ('a', 1) y I'm just wondering if it really makes sense to keep a MultiIndex for a coordinate that is not a dimension anymore like in this case. And this is just a nonsense :) Sorry it is late! Yep I agree it would be nice to have scalar coordinates in both cases. ","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,228295383 https://github.com/pydata/xarray/issues/1408#issuecomment-301351084,https://api.github.com/repos/pydata/xarray/issues/1408,301351084,MDEyOklzc3VlQ29tbWVudDMwMTM1MTA4NA==,4160723,2017-05-15T00:33:15Z,2017-05-15T00:33:15Z,MEMBER,"The current behavior is actually dictated by pandas and I think it was initially intentional (before we could access MultiIndex levels as virtual coordinates). In the first example `MultiIndex.get_loc_level()` is called, which doesn't return a `MutliIndex`: ```python In [11]: mdix = ds.yx.to_index() In [12]: midx.get_loc_level(2, level='x') Out[12]: (array([False, True, False, False, True, False], dtype=bool), Index(['a', 'b'], dtype='object', name='y')) ``` If we want to keep the `MultiIndex` in this case, then I think we can just ignore `new_indexes` returned by `indexing.remap_label_indexers` and remove [Dataset._replace_indexes](https://github.com/pydata/xarray/blob/80ddad99dbee1197c93f61ef9048b83d9f29d00d/xarray/core/dataset.py#L578). But we still have to choose whether automatically renaming the dimension makes sense or not, i.e., choose between ```python In [5]: ds.sel(x=2) Out[5]: Dimensions: (yx: 2) Coordinates: * yx MultiIndex - y (yx) object 'a' 'b' - x (yx) int64 2 2 Data variables: foo (yx) int64 2 5 ``` and ```python In [5]: ds.sel(x=2) Out[5]: Dimensions: (y: 2) Coordinates: * y (y) object 'a' 'b' x (y) int64 2 2 Data variables: foo (y) int64 2 5 ``` --- The second issue is also due to how MultiIndex works in pandas: ```python In [10]: midx[0] Out[10]: ('a', 1) In [11]: midx[[0, 1]] Out[11]: MultiIndex(levels=[['a', 'b'], [1, 2, 3]], labels=[[0, 0], [0, 1]], names=['y', 'x']) ``` I'm just wondering if it really makes sense to keep a MultiIndex for a coordinate that is not a dimension anymore like in this case. ","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,228295383