Skip to content

added test to indexing on groupby, #32464 #44046

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

Closed
wants to merge 16 commits into from
Closed
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
12 changes: 12 additions & 0 deletions pandas/tests/groupby/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,3 +285,15 @@ def test_column_axis(column_group_df):
expected = column_group_df.iloc[:, [1, 3]]

tm.assert_frame_equal(result, expected)


def test_if_is_multiindex():
# GH 32464
# Test if index after groupby with more then one column is always MultiIndex
a = pd.DataFrame({"a": [], "b": [], "c": []})

index_1 = a.groupby(["a", "b"]).sum().index
index_2 = a.groupby(["a", "b", "c"]).sum().index
Copy link
Member

Choose a reason for hiding this comment

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

Instead could you construct the full DataFrame result of a.groupby(["a", "b", "c"]).sum() and a.groupby(["a", "b"]).sum() and use tm.assert_frame_equal?

Also could you move this test to a more appropriate groupby testing file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @mroeschke, I changed it so it uses tm.assert_frame_equal, but I'm not sure what the appropriate testing file would be.

Copy link
Member

Choose a reason for hiding this comment

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

Probably pandas/tests/groupby/test_function.py


assert isinstance(index_2, pd.core.indexes.multi.MultiIndex)
assert type(index_1) == type(index_2)