-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: Support mask in duplicated algorithm #48150
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 8 commits
0cf2abe
b40deb1
1b1fb11
fe63bad
308cd94
4cabede
8d58b9e
c5226a4
a1ae1d8
801134b
d9a89fa
a334865
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 |
---|---|---|
|
@@ -1043,6 +1043,10 @@ def duplicated( | |
------- | ||
duplicated : ndarray[bool] | ||
""" | ||
if hasattr(values, "dtype") and isinstance(values.dtype, BaseMaskedDtype): | ||
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 assumes, that we don't want to add duplicated to the ea interface 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. Might be good to add an issue to discuss this. Kinda unfortunate we need this exception for 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. Yeah not happy about this either, will open a follow up issue to discuss |
||
values = cast("BaseMaskedArray", values) | ||
return htable.duplicated(values._data, keep=keep, mask=values._mask) | ||
|
||
values = _ensure_data(values) | ||
return htable.duplicated(values, keep=keep) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
import pytest | ||
|
||
from pandas import ( | ||
NA, | ||
Categorical, | ||
Series, | ||
) | ||
|
@@ -50,3 +51,15 @@ def test_duplicated_categorical_bool_na(nulls_fixture): | |
result = ser.duplicated() | ||
expected = Series([False, False, True, True, False]) | ||
tm.assert_series_equal(result, expected) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"keep, vals", | ||
[("last", [True, False]), ("first", [False, True]), (False, [True, True])], | ||
) | ||
def test_duplicated_mask(keep, vals): | ||
# GH#48150 | ||
ser = Series([1, 2, NA, NA], dtype="Int64") | ||
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. Nit: Could you add one more
Doesn't have coverage with this 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. Good point, thx. Added 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. But we should probably also cover the case when 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. thx, this found a bug, we did not set |
||
result = ser.duplicated(keep=keep) | ||
expected = Series([False, False] + vals) | ||
tm.assert_series_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.
Would be nice if we could template
for i in ...
based on{{ if keep == "first"/"last" }}
to deduplicate this similar logic, but could be a follow up.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.
Oh good idea, would do as a follow up to keep diff reviewable.