Skip to content

Groupby Agg not working if different partials with same name on the same column #45075

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
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions pandas/tests/groupby/aggregate/test_aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,26 @@ def test_agg_ser_multi_key(df):
tm.assert_series_equal(results, expected)


def test_agg_different_partials():
# GH 28570

quant50 = partial(np.percentile, q=50)
quant50.__name__ = "quant50"
quant70 = partial(np.percentile, q=70)
quant70.__name__ = "quant70"

df = pd.DataFrame({"col1": ["a", "a", "b", "b", "b"], "col2": [1, 2, 3, 4, 5]})
result = df.groupby("col1").agg({"col2": [quant50, quant70]})

expected = pd.DataFrame(
{"col1": ["a", "b"], "quant50": [1.5, 4.0], "quant70": [1.7, 4.4]}
)
expected = expected.set_index("col1")
expected.columns = pd.MultiIndex.from_product([["col2"], expected.columns])

tm.assert_frame_equal(result, expected)


def test_groupby_aggregation_mixed_dtype():
# GH 6212
expected = DataFrame(
Expand Down