Skip to content

Commit

Permalink
Code style chore (Pre-commit hook)
Browse files Browse the repository at this point in the history
  • Loading branch information
AshmitGupta committed Sep 1, 2024
1 parent 14de84b commit 208d2fc
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions pandas/tests/groupby/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -3004,31 +3004,37 @@ def test_groupby_agg_namedagg_with_duplicate_columns():

tm.assert_frame_equal(result, expected)


class MyDataFrame(DataFrame):
@property
def _constructor(self):
return MyDataFrame

@pytest.mark.parametrize("data, agg_dict, expected", [
pytest.param(
{"A": [1, 1, 2, 2], "B": [1, 2, 3, 4]},
{"B": "sum"},
DataFrame({"B": [3, 7]}, index=Index([1, 2], name="A"))
),
pytest.param(
{"A": [1, 1, 2, 2], "B": [1, 2, 3, 4], "C": [4, 3, 2, 1]},
{"B": "sum", "C": "mean"},
DataFrame({"B": [3, 7], "C": [3.5, 1.5]}, index=Index([1, 2], name="A"))
),
])

@pytest.mark.parametrize(
"data, agg_dict, expected",
[
pytest.param(
{"A": [1, 1, 2, 2], "B": [1, 2, 3, 4]},
{"B": "sum"},
DataFrame({"B": [3, 7]}, index=Index([1, 2], name="A")),
),
pytest.param(
{"A": [1, 1, 2, 2], "B": [1, 2, 3, 4], "C": [4, 3, 2, 1]},
{"B": "sum", "C": "mean"},
DataFrame({"B": [3, 7], "C": [3.5, 1.5]}, index=Index([1, 2], name="A")),
),
],
)
def test_groupby_agg_preserves_subclass(data, agg_dict, expected):
# GH#59667
df = MyDataFrame(data)
result = df.groupby("A").agg(agg_dict)

assert isinstance(result, MyDataFrame)
tm.assert_frame_equal(result, expected)


def test_groupby_multi_index_codes():
# GH#54347
df = DataFrame(
Expand Down

0 comments on commit 208d2fc

Please sign in to comment.