-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: Avoid ambiguous condition in GroupBy.first / last #32124
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
627410d
bb4ad11
3213718
58bbb57
4f2d126
c4a6518
e09bbe6
c7c7a95
4329021
87456af
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 |
---|---|---|
|
@@ -530,3 +530,20 @@ def test_nth_nan_in_grouper(dropna): | |
) | ||
|
||
tm.assert_frame_equal(result, expected) | ||
|
||
|
||
@pytest.mark.parametrize("method", ["first", "last"]) | ||
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. can you also test 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. Added a test for nth with nulls; I gave it its own test rather than putting it with first / last to avoid too much awkward if / else branching inside the test |
||
def test_first_last_with_na_object(method): | ||
# https://github.com/pandas-dev/pandas/issues/32123 | ||
groups = pd.DataFrame({"a": [1, 1, 2, 2], "b": [1, 2, 3, pd.NA]}).groupby("a") | ||
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. Should also use nulls_fixture here after #31799 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. Can you merge master? This should be available now |
||
result = getattr(groups, method)() | ||
|
||
if method == "first": | ||
values = {"b": [1, 3]} | ||
else: | ||
values = {"b": [2, 3]} | ||
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. This raises a question (that perhaps should be handled in another issue). 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. It seems that |
||
|
||
idx = pd.Index([1, 2], name="a") | ||
expected = pd.DataFrame(values, index=idx) | ||
|
||
tm.assert_frame_equal(result, expected) |
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 can use the
checknull
function from missing insteadThere 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.
Maybe just
not checknull(val)
for the whole condition? I think there was an issue withchecknull
not catchingdecimal.Decimal("nan")
but I could try to add that here