Skip to content

groupby.agg should refuse non-aggregation operations #26743

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ghost opened this issue Jun 8, 2019 · 1 comment
Closed

groupby.agg should refuse non-aggregation operations #26743

ghost opened this issue Jun 8, 2019 · 1 comment

Comments

@ghost
Copy link

ghost commented Jun 8, 2019

Since groupby.agg() is, "by definition a reducer." (in other words, produces one value per series in a group), it seems odd that it accepts non-aggregating operations such as 'rank':

Related to #22509 (comment) where groupby.transform('rank') applies the wrong code path to 'rank'
because it is treated as an aggregator (array->scalar) instead of a shape-preserving operation.

In [82]: df=pd.DataFrame(dict(price=[1,2,2,3,3,3],cost=(1,2,1,3,2,1)))
    ...: df
Out[82]: 
   price  cost
0      1     1
1      2     2
2      2     1
3      3     3
4      3     2
5      3     1

In [83]: g=df.groupby('price')
    ...: g.agg('rank').astype(int)
Out[83]: 
   cost
0     1
1     2
2     1
3     3
4     2
5     1```
@ghost
Copy link
Author

ghost commented Jul 14, 2019

superseded by #27389

@ghost ghost closed this as completed Jul 14, 2019
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants