Skip to content

Commit

Permalink
CLN: improve is_unique check in Index.intersection (#38154)
Browse files Browse the repository at this point in the history
  • Loading branch information
phofl authored Dec 2, 2020
1 parent 7e2aa42 commit 8a15ae9
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2380,6 +2380,10 @@ def unique(self, level=None):
"""
if level is not None:
self._validate_index_level(level)

if self.is_unique:
return self._shallow_copy()

result = super().unique()
return self._shallow_copy(result)

Expand Down Expand Up @@ -2866,7 +2870,7 @@ def _intersection(self, other, sort=False):
result = algos.safe_sort(result)

# Intersection has to be unique
assert algos.unique(result).shape == result.shape
assert Index(result).is_unique

return result

Expand Down

0 comments on commit 8a15ae9

Please sign in to comment.