Update group by multi index
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.2k
- Forks
- 1.4k
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 14
Description
ideally GroupBy._infer_concat_args() would return a xr.Coordinates object that contains both the coordinate(s) and their (multi-)index to assign to the result (combined) object.
The goal is to avoid calling create_default_index_implicit(coord) below where coord is a pd.MultiIndex or a single IndexVariable wrapping a multi-index. If coord is a Coordinates object, we could do combined = combined.assign_coords(coord) instead.
There are actually more general issues:
- The
groupparameter of Dataset.groupby being a single variable or variable name, it won't be possible to do groupby on a full pandas multi-index once we drop its dimension coordinate (#8143). How can we still support it? Maybe passing a dimension name togroupand check that there's only one index for that dimension? - How can we support custom, multi-coordinate indexes with groupby? I don't have any practical example in mind, but in theory just passing a single coordinate name as
groupwill invalidate the index. Should we drop the index in the result? Or, like suggested above pass a dimension name as group and check the index?
Originally posted by @benbovy in https://github.com/pydata/xarray/issues/8140#issuecomment-1709775666
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/groupby.py around lines 1573-1587 and inspect GroupBy._infer_concat_args(), especially how MultiIndex and IndexVariable values reach create_default_index_implicit(). Then resolve the broader groupby behavior questions for full pandas multi-indexes and custom multi-coordinate indexes; done means the intended coordinate and index behavior is defined and supported.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- pandas, python
- Domain
- data
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100