Skip to content
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

BUG: Fix Series.is_unique with single occurrence of NaN #25182

Merged
merged 3 commits into from
Feb 8, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.24.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Bug Fixes

**Other**

-
- Bug in :meth:`Series.is_unique` where single occurrences of ``NaN`` were not considered unique (:issue:`25180`)
-
-

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1345,7 +1345,7 @@ def is_unique(self):
-------
is_unique : boolean
"""
return self.nunique() == len(self)
return self.nunique(dropna=False) == len(self)

@property
def is_monotonic(self):
Expand Down
19 changes: 13 additions & 6 deletions pandas/tests/series/test_duplicates.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,19 @@ def test_unique_data_ownership():
Series(Series(["a", "c", "b"]).unique()).sort_values()


def test_is_unique():
# GH11946
s = Series(np.random.randint(0, 10, size=1000))
assert s.is_unique is False
s = Series(np.arange(1000))
assert s.is_unique is True
@pytest.mark.parametrize('data, expected', [
jschendel marked this conversation as resolved.
Show resolved Hide resolved
(np.random.randint(0, 10, size=1000), False),
(np.arange(1000), True),
([], True),
([np.nan], True),
(['foo', 'bar', np.nan], True),
(['foo', 'foo', np.nan], False),
(['foo', 'bar', np.nan, np.nan], False)])
def test_is_unique(data, expected):
# GH11946 / GH25180
s = Series(data)
result = s.is_unique
assert result is expected


def test_is_unique_class_ne(capsys):
Expand Down