Skip to content

Commit

Permalink
Avoid DeprecationWarning by setting include_groups=False in apply
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Mok authored and Jason Mok committed May 8, 2024
1 parent c0c41f4 commit 321b8ff
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions pandas/tests/groupby/test_grouping.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,12 +845,9 @@ def test_groupby_tuple_keys_handle_multiindex(self):
}
)
expected = df.sort_values(by=["category_tuple", "num1"])

msg = "DataFrameGroupBy.apply operated on the grouping columns"
with tm.assert_produces_warning(DeprecationWarning, match=msg):
result = df.groupby("category_tuple").apply(
lambda x: x.sort_values(by="num1")
)
result = df.groupby("category_tuple").apply(
lambda x: x.sort_values(by="num1"), include_groups=False
)
expected = expected[result.columns]
tm.assert_frame_equal(result.reset_index(drop=True), expected)

Expand Down

0 comments on commit 321b8ff

Please sign in to comment.