-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: None converted to NaN after groupby first and last #33462
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 1 commit
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 |
---|---|---|
|
@@ -893,7 +893,7 @@ def group_last(rank_t[:, :] out, | |
for j in range(K): | ||
val = values[i, j] | ||
|
||
if not checknull(val): | ||
if not checknull(val) or val is None: | ||
# NB: use _treat_as_na here once | ||
# conditional-nogil is available. | ||
nobs[lab, j] += 1 | ||
|
@@ -986,7 +986,7 @@ def group_nth(rank_t[:, :] out, | |
for j in range(K): | ||
val = values[i, j] | ||
|
||
if not checknull(val): | ||
if not checknull(val) or val is None: | ||
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. same 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. Done |
||
# NB: use _treat_as_na here once | ||
# conditional-nogil is available. | ||
nobs[lab, j] += 1 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,6 +94,16 @@ def test_nth_with_na_object(index, nulls_fixture): | |
tm.assert_frame_equal(result, expected) | ||
|
||
|
||
@pytest.mark.parametrize("method", ["first", "last"]) | ||
def test_first_last_with_None(method): | ||
# https://github.com/pandas-dev/pandas/issues/32800 | ||
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 add a comment, that we wish to preserve None in object dtypes. 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. Done |
||
df = pd.DataFrame.from_dict({"id": ["a"], "value": [None]}) | ||
groups = df.groupby("id", as_index=False) | ||
result = getattr(groups, method)() | ||
|
||
tm.assert_frame_equal(result, df) | ||
|
||
|
||
def test_first_last_nth_dtypes(df_mixed_floats): | ||
|
||
df = df_mixed_floats.copy() | ||
|
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.
can you add a comment here of why we are doing this
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.
Done