sel(method=x) is not propagated for MultiIndex
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.2k
- Forks
- 1.4k
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 14
Description
When passing a method different from None to the selection method (e.g. .sel(method='nearest')), it is not propagated if the index is a MultiIndex.
Specifically, the passing of the method key seems to be missing in xarray/core/indexing.py:convert_label_indexer https://github.com/pydata/xarray/blob/0811141e8f985a1f3b95ead92c3850cc74e160a5/xarray/core/indexing.py#L158-L159
For a normal index, the method is passed properly: https://github.com/pydata/xarray/blob/0811141e8f985a1f3b95ead92c3850cc74e160a5/xarray/core/indexing.py#L181
This leads to an unexpected KeyError when the selection value is not in the index, even if a nearest value could have been found.
Output of xr.show_versions()
xarray: 0.10.8
pandas: 0.24.2
numpy: 1.16.2
scipy: 1.1.0
netCDF4: 1.4.2
h5netcdf: None
h5py: 2.8.0
Nio: None
zarr: None
bottleneck: None
cyordereddict: None
dask: 0.20.0
distributed: None
matplotlib: 3.0.1
cartopy: None
seaborn: 0.9.0
setuptools: 40.8.0
pip: 19.0.3
conda: None
pytest: 3.10.0
IPython: 7.1.1
sphinx: None
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in xarray/core/indexing.py at convert_label_indexer, comparing the MultiIndex path with the normal-index path where method is passed. Reproduce a .sel(method='nearest') lookup on a MultiIndex whose requested value is absent. Done means nearest selection no longer raises the unexpected KeyError when a suitable indexed value exists.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- pandas, python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100