Skip to content

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

Closed
@rhshadrach

Description

@rhshadrach
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.

Metadata

Metadata

Assignees

Labels

API - ConsistencyInternal Consistency of API/BehaviorApplyApply, Aggregate, Transform, MapBugGroupby

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions