Skip to content
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

BUG: groupby.apply doesn't allow passing args/kwargs with a str func #46479

Closed
rhshadrach opened this issue Mar 23, 2022 · 0 comments · Fixed by #46481
Closed

BUG: groupby.apply doesn't allow passing args/kwargs with a str func #46479

rhshadrach opened this issue Mar 23, 2022 · 0 comments · Fixed by #46481
Assignees
Labels
API - Consistency Internal Consistency of API/Behavior Apply Apply, Aggregate, Transform, Map Bug Groupby
Milestone

Comments

@rhshadrach
Copy link
Member

rhshadrach commented Mar 23, 2022

import numpy as np
import pandas as pd

df = pd.DataFrame({"A": np.random.randint(0, 3, 10), "B": 1, "C": 'x'})
gb = df.groupby("A")
result = gb.agg("sum", numeric_only=True)
expected = gb.sum(numeric_only=True)
pd.testing.assert_frame_equal(result, expected)

This raises on the result = ... line. However, it works with agg and transform. E.g.

df = pd.DataFrame({"A": np.random.randint(0, 3, 10), "B": 1, "C": 'x'})
gb = df.groupby("A")
print(gb.agg("sum", numeric_only=False))
print(gb.transform("sum", numeric_only=False))

produces

   B     C
A         
0  3   xxx
1  4  xxxx
2  3   xxx
   B     C
0  3   xxx
1  4  xxxx
2  3   xxx
3  3   xxx
4  4  xxxx
5  4  xxxx
6  4  xxxx
7  3   xxx
8  3   xxx
9  3   xxx

I ran into this while working on #46072. There are tests which use apply that would raise a warning about the changing default; at the current state a user would not be able to silence the warning.

@rhshadrach rhshadrach added Bug Groupby Apply Apply, Aggregate, Transform, Map API - Consistency Internal Consistency of API/Behavior labels Mar 23, 2022
@rhshadrach rhshadrach self-assigned this Mar 23, 2022
@jreback jreback added this to the 1.5 milestone Mar 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API - Consistency Internal Consistency of API/Behavior Apply Apply, Aggregate, Transform, Map Bug Groupby
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants