-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Groupby selection context not being properly reset #28541
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
Changes from 3 commits
b5f01b7
1dbb12d
bcab4a0
ca26b64
c4b0a53
7a9e1d1
f24c05c
5cc3cb1
3050963
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -433,6 +433,33 @@ def test_frame_groupby_columns(tsframe): | |
assert len(v.columns) == 2 | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"func, args", | ||
[ | ||
("sum", []), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DO we need all these parametrezations? Or does just a few work? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably not. It looks like one of [sum, prod, min, max, first, last] and then nth would suffice. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have a |
||
("prod", []), | ||
("min", []), | ||
("max", []), | ||
("nth", [0]), | ||
("last", []), | ||
("first", []), | ||
], | ||
) | ||
def test_frame_groupby_avoids_mutate(func, args): | ||
# GH28523 | ||
df = pd.DataFrame({"A": ["foo", "bar", "foo", "bar"], "B": [1, 2, 3, 4]}) | ||
grouped = df.groupby("A") | ||
|
||
expected = grouped.apply(lambda x: x) | ||
|
||
fn = getattr(grouped, func) | ||
fn(*args) | ||
WillAyd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
result = grouped.apply(lambda x: x) | ||
|
||
tm.assert_frame_equal(expected, result) | ||
|
||
|
||
def test_frame_set_name_single(df): | ||
grouped = df.groupby("A") | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the ref needs to be :class:`pandas.core.groupby.DataFrameGroupBy`. And maybe briefly explain the user-visible behavior: "Multiple operations on a DataFrameGroupBy object not giving the same results in certain cases".