Skip to content

TST: Add test for groupby aggregatation with nested dictionary #50079

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
Changes from 2 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
10 changes: 10 additions & 0 deletions pandas/tests/groupby/aggregate/test_aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,16 @@ def test_groupby_agg_coercing_bools():
tm.assert_series_equal(result, expected)


def test_groupby_agg_nested_dictionary():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're not testing nested dictionaries here, so I think this name is misleading. I think we test dictionary behavior elsewhere, what seems likely to be novel about this test is that you are using [["B"]]; this calls the function _gotitem in the groupby code. So I'd suggest a name like: test_groupby_agg_dict_with_gotitem

Copy link
Member

@rhshadrach rhshadrach Dec 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getitem (as in the dunder __getitem__) would also work - actually, the more I think about it, the more I'd prefer getitem.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

# issue 25471
dat = DataFrame({"A": ["A", "A", "B", "B", "B"], "B": [1, 2, 1, 1, 2]})
result = dat.groupby("A")[["B"]].agg({"B": "sum"})

expected = DataFrame({"B": [3, 4]}, index=["A", "B"]).rename_axis("A", axis=0)

tm.assert_frame_equal(result, expected)


@pytest.mark.parametrize(
"op",
[
Expand Down