Skip to content
Merged
Changes from 1 commit
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
8 changes: 8 additions & 0 deletions pandas/tests/groupby/aggregate/test_aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,14 @@ def test_groupby_agg_coercing_bools():
expected = Series([True, False], index=index, name="c")
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