Skip to content

TST: Test GroupBy.__getitem__ with a column from grouper #55193

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

Merged
merged 1 commit into from
Sep 19, 2023
Merged
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
14 changes: 14 additions & 0 deletions pandas/tests/groupby/test_grouping.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,20 @@ def test_getitem_single_column(self):

tm.assert_series_equal(result, expected)

@pytest.mark.parametrize(
"func", [lambda x: x.sum(), lambda x: x.agg(lambda y: y.sum())]
)
def test_getitem_from_grouper(self, func):
# GH 50383
df = DataFrame({"a": [1, 1, 2], "b": 3, "c": 4, "d": 5})
gb = df.groupby(["a", "b"])[["a", "c"]]

idx = MultiIndex.from_tuples([(1, 3), (2, 3)], names=["a", "b"])
expected = DataFrame({"a": [2, 2], "c": [8, 4]}, index=idx)
result = func(gb)

tm.assert_frame_equal(result, expected)

def test_indices_grouped_by_tuple_with_lambda(self):
# GH 36158
df = DataFrame(
Expand Down