Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add unique check to Index.unique
  • Loading branch information
phofl committed Nov 29, 2020
commit cd1accad31d7ff2f13705c919f574c4caaa0288f
10 changes: 5 additions & 5 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2379,6 +2379,10 @@ def unique(self, level=None):
"""
if level is not None:
self._validate_index_level(level)

if self.is_unique:
return self
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs to return self._shallow_copy()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx.


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

Expand Down Expand Up @@ -2858,11 +2862,7 @@ def _intersection(self, other, sort=False):
indexer = algos.unique1d(Index(rvals).get_indexer_non_unique(lvals)[0])
indexer = indexer[indexer != -1]

result = other.take(indexer)
if not result.is_unique:
result = result.unique()._values
else:
result = result._values
result = other.take(indexer).unique()._values

if sort is None:
result = algos.safe_sort(result)
Expand Down