Reimplement GroupBy.argmax
Open
Nobody has claimed this yet.
regression
topic-groupby
- Dominant language
- Python
- Stars
- 4.2k
- Forks
- 1.4k
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 14
Description
Please implement
Is your feature request related to a problem? Please describe.
Observed:
da.groupby("g").argmax(dim="t")
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-84-15c199b0f7d4> in <module>
----> 1 da.groupby("g").argmax(dim="t")
AttributeError: 'DataArrayGroupBy' object has no attribute 'argmax'
Describe the solution you'd like
Expected: Vector of length len(unique(g)) containing the indices of da["t"] where the value was maximum.
Workaround:
da.groupby("g").apply(lambda c: c.argmax(dim="t"))
<xarray.DataArray 'da' (st: 11, g: 1)>
array([[ 7],
[ 0],
[14],
[14],
[ 0],
[ 0],
[ 7],
[ 0],
[14],
[ 0],
[ 7]])
Coordinates:
* st (st) object 'a' ... 'z'
* g (g) object 'E'
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 from the DataArrayGroupBy entry point implicated by the missing argmax method and compare it with existing groupby reduction methods. Use the reported da.groupby("g").argmax(dim="t") case as the starting check; done means it returns one maximum-index value per unique g, matching the expected result and workaround.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100