Skip to content

Commit 05c130d

Browse files
authored
REF: Index._intersection (#37885)
1 parent e71210e commit 05c130d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

pandas/core/indexes/base.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -2798,6 +2798,13 @@ def intersection(self, other, sort=False):
27982798
other = other.astype("O")
27992799
return this.intersection(other, sort=sort)
28002800

2801+
result = self._intersection(other, sort=sort)
2802+
return self._wrap_setop_result(other, result)
2803+
2804+
def _intersection(self, other, sort=False):
2805+
"""
2806+
intersection specialized to the case with matching dtypes.
2807+
"""
28012808
# TODO(EA): setops-refactor, clean all this up
28022809
lvals = self._values
28032810
rvals = other._values
@@ -2808,7 +2815,7 @@ def intersection(self, other, sort=False):
28082815
except TypeError:
28092816
pass
28102817
else:
2811-
return self._wrap_setop_result(other, result)
2818+
return result
28122819

28132820
try:
28142821
indexer = Index(rvals).get_indexer(lvals)
@@ -2824,7 +2831,7 @@ def intersection(self, other, sort=False):
28242831
if sort is None:
28252832
result = algos.safe_sort(result)
28262833

2827-
return self._wrap_setop_result(other, result)
2834+
return result
28282835

28292836
def difference(self, other, sort=None):
28302837
"""

0 commit comments

Comments
 (0)