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-448817147,https://api.github.com/repos/pydata/xarray/issues/2621,448817147,MDEyOklzc3VlQ29tbWVudDQ0ODgxNzE0Nw==,1217238,2018-12-20T01:07:27Z,2018-12-20T01:07:27Z,MEMBER,"> This issue does not matter only in unstack but also in sel (reindex also?).
Can you explain why matters for `.sel()`? I guess it slows down repeated indexing?
My inclination was just to copy what pandas does (which is only removing unused levels in `unstack`)","{""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
https://github.com/pydata/xarray/pull/2621#issuecomment-448677802,https://api.github.com/repos/pydata/xarray/issues/2621,448677802,MDEyOklzc3VlQ29tbWVudDQ0ODY3NzgwMg==,1217238,2018-12-19T17:26:36Z,2018-12-19T17:26:36Z,MEMBER,"Should we update levels after indexing or when stacking? Pandas does the later:
```
In [31]: import pandas as pd
In [32]: mindex = pd.MultiIndex.from_product([[1, 2, 3], ['a', 'b']])
In [33]: s = pd.Series(range(6), mindex)
In [34]: s.loc[:1].index
Out[34]:
MultiIndex(levels=[[1, 2, 3], ['a', 'b']],
labels=[[0, 0], [0, 1]])
In [35]: s.loc[:1].unstack()
Out[35]:
a b
1 0 1
```
The advantage of waiting until unstacking is that removing unused levels could be expensive compared to indexing: it runs in time O(L+N), where L is the size of the original level and N is the length of the new multi-index.","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,392535505