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/pull/2621#issuecomment-448909559,https://api.github.com/repos/pydata/xarray/issues/2621,448909559,MDEyOklzc3VlQ29tbWVudDQ0ODkwOTU1OQ==,6815844,2018-12-20T08:09:09Z,2018-12-20T08:09:09Z,MEMBER,I moved `MultiIndex.remove_unused_levels()` to the inside of `unstack`. Now it is invoked only when `unstack` is called.,"{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,392535505 https://github.com/pydata/xarray/pull/2621#issuecomment-448894775,https://api.github.com/repos/pydata/xarray/issues/2621,448894775,MDEyOklzc3VlQ29tbWVudDQ0ODg5NDc3NQ==,6815844,2018-12-20T06:59:43Z,2018-12-20T06:59:43Z,MEMBER,But this problem of `.sel` can be simply solved by manually raising a keyerror if the result of get_loc is size 0 array.,"{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,392535505 https://github.com/pydata/xarray/pull/2621#issuecomment-448887168,https://api.github.com/repos/pydata/xarray/issues/2621,448887168,MDEyOklzc3VlQ29tbWVudDQ0ODg4NzE2OA==,6815844,2018-12-20T06:22:38Z,2018-12-20T06:22:38Z,MEMBER,"@shoyer > My inclination was just to copy what pandas does (which is only removing unused levels in unstack) Thanks. I will take a look the source later. > Can you explain why matters for .sel()? Selection of non-exsiting level variable should be KeyError, but it gives a 0-size index. ```python In [8]: ds = xr.DataArray(np.arange(40).reshape(8, 5), dims=['x', 'y'], coords={'x': np.arange(8), 'y': np.arange(5)}).stack(xy=['x', 'y']) In [9]: ds.isel(xy=ds['x'] < 4).sel(x=5) # should be KeyError Out[9]: array([], dtype=int64) Coordinates: * y (y) int64 ``` ","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,392535505 https://github.com/pydata/xarray/pull/2621#issuecomment-448752816,https://api.github.com/repos/pydata/xarray/issues/2621,448752816,MDEyOklzc3VlQ29tbWVudDQ0ODc1MjgxNg==,6815844,2018-12-19T21:38:18Z,2018-12-19T21:38:18Z,MEMBER,"@shoyer This issue does not matter only in `unstack` but also in `sel` (reindex also?). We can do it in both methods for efficiency, but I just prefered to do it in one place for the quick fix. But what is the good place to do it actually? If we invoke this in `sel`, it would be again inefficient as this is called every time we did `.sel`. Probably the best for the efficiency is to keep a flag for it in `PandasIndexAdapter` and do it in `_get_item_with_mask` and `get_loc` only if flag is raised?","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,392535505