-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: nunique not ignoring both None and np.nan #37607
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 4 commits
4f5f7eb
25cd909
7f91c90
8c9e2d5
1de2b48
89dc4d7
30e0f10
aff0b01
52d47e3
aaf14e2
d26e523
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 |
---|---|---|
|
@@ -1032,10 +1032,11 @@ def nunique(self, dropna: bool = True) -> int: | |
>>> s.nunique() | ||
4 | ||
""" | ||
uniqs = self.unique() | ||
if dropna: | ||
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. I'd do obj = self.dropna() if dropna else self
return len(obj.unique()) |
||
uniqs = self.dropna().unique() | ||
else: | ||
uniqs = self.unique() | ||
n = len(uniqs) | ||
if dropna and isna(uniqs).any(): | ||
n -= 1 | ||
return n | ||
|
||
@property | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,3 +121,11 @@ def test_unique_bad_unicode(idx_or_series_w_bad_unicode): | |
else: | ||
expected = np.array(["\ud83d"], dtype=object) | ||
tm.assert_numpy_array_equal(result, expected) | ||
|
||
|
||
def test_nunique_dropna(): | ||
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. Parametrize on |
||
# test for #37566 | ||
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 |
||
s = pd.Series(['yes', 'yes', pd.NA, np.nan, None, pd.NaT]) | ||
res = s.nunique(dropna=True) | ||
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. just do 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.
|
||
expected = 1 | ||
assert res == 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.