Skip to content

Commit 8a15ae9

Browse files
authored
CLN: improve is_unique check in Index.intersection (#38154)
1 parent 7e2aa42 commit 8a15ae9

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

pandas/core/indexes/base.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -2380,6 +2380,10 @@ def unique(self, level=None):
23802380
"""
23812381
if level is not None:
23822382
self._validate_index_level(level)
2383+
2384+
if self.is_unique:
2385+
return self._shallow_copy()
2386+
23832387
result = super().unique()
23842388
return self._shallow_copy(result)
23852389

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

28682872
# Intersection has to be unique
2869-
assert algos.unique(result).shape == result.shape
2873+
assert Index(result).is_unique
28702874

28712875
return result
28722876

0 commit comments

Comments
 (0)