Boolean indexing with multi-dimensional key arrays
Open
Nobody has claimed this yet.
contrib-good-first-issue
topic-indexing
- Dominant language
- Python
- Stars
- 4.2k
- Forks
- 1.4k
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 14
Description
Originally from https://github.com/pydata/xarray/issues/974
For boolean indexing:
da[key]wherekeyis a boolean labelled array (with any number of dimensions) is made equivalent toda.where(key.reindex_like(ds), drop=True). This matches the existing behavior ifkeyis a 1D boolean array. For multi-dimensional arrays, even though the result is now multi-dimensional, this coupled with automatic skipping of NaNs means thatda[key].mean()gives the same result as in NumPy.da[key] = valuewherekeyis a boolean labelled array can be made equivalent toda = da.where(*align(key.reindex_like(da), value.reindex_like(da)))(that is, the three argument form ofwhere).da[key_0, ..., key_n]where all ofkey_iare boolean arrays gets handled in the usual way. It is anIndexingErrorto supply multiple labelled keys if any of them are not already aligned with as the corresponding index coordinates (and share the same dimension name). If they want alignment, we suggest users simply writeda[key_0 & ... & key_n].
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
No implementation files, tests, or entry points are named. Start by tracing the existing boolean-indexing behavior and comparing it with the three cases described here; done means the proposed labeled-array indexing and assignment semantics work consistently, including alignment errors for multiple keys.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, pandas, python
- Domain
- data
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100