Skip to content

BUG: GroupBy Aggregation Behavior #39489

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
clampr opened this issue Jan 30, 2021 · 3 comments
Closed

BUG: GroupBy Aggregation Behavior #39489

clampr opened this issue Jan 30, 2021 · 3 comments
Assignees
Labels
Apply Apply, Aggregate, Transform, Map Bug Groupby

Comments

@clampr
Copy link

clampr commented Jan 30, 2021


Question About GroupBy Aggregation Behavior

I observed a behavior of the Pandas GroupBy method agg() which I cannot explain based on the docs.

I want to perform a custom aggregation on a grouped DataFrame. Let's take this code snippet:

def aggregate_point(x):
 print(x)
 exit()

data = data.groupby(
 pd.Grouper(level='time', freq='1H')).agg(aggregate_point)

This prints a Series for each group.

However, when I pass any additional parameter to aggregate_point, the full DataFrame is being printed:

def aggregate_point(x, score):
 print(x)
 exit()

data = data.groupby(
 pd.Grouper(level='time', freq='1H')).agg(aggregate_point, score=True)

Why does the score parameter influence the value of x (DataFrame vs. Series)?

@clampr clampr added Needs Triage Issue that has not been reviewed by a pandas team member Usage Question labels Jan 30, 2021
@rhshadrach
Copy link
Member

This is a bug, related to #39169. The addition of a parameter should not have this influence.

@rhshadrach rhshadrach added Apply Apply, Aggregate, Transform, Map Bug Groupby and removed Needs Triage Issue that has not been reviewed by a pandas team member Usage Question labels Jan 30, 2021
@rhshadrach rhshadrach added this to the Contributions Welcome milestone Jan 30, 2021
@rhshadrach rhshadrach changed the title QST: GroupBy Aggregation Behavior BUG: GroupBy Aggregation Behavior Jan 30, 2021
@jnchngc
Copy link

jnchngc commented Apr 10, 2021

take

@mroeschke
Copy link
Member

Closing at this appears identical to #39169

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Apply Apply, Aggregate, Transform, Map Bug Groupby
Projects
None yet
Development

No branches or pull requests

4 participants