Skip to content

Commit

Permalink
TST: Test GroupBy.__getitem__ with a column from grouper (#55193)
Browse files Browse the repository at this point in the history
  • Loading branch information
ihsansecer authored Sep 19, 2023
1 parent df7c0b7 commit 8352331
Showing 1 changed file with 14 additions and 0 deletions.
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

0 comments on commit 8352331

Please sign in to comment.