diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index cb5641a74e60b..3243fcf0742a0 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -2798,6 +2798,13 @@ def intersection(self, other, sort=False): other = other.astype("O") return this.intersection(other, sort=sort) + result = self._intersection(other, sort=sort) + return self._wrap_setop_result(other, result) + + def _intersection(self, other, sort=False): + """ + intersection specialized to the case with matching dtypes. + """ # TODO(EA): setops-refactor, clean all this up lvals = self._values rvals = other._values @@ -2808,7 +2815,7 @@ def intersection(self, other, sort=False): except TypeError: pass else: - return self._wrap_setop_result(other, result) + return result try: indexer = Index(rvals).get_indexer(lvals) @@ -2824,7 +2831,7 @@ def intersection(self, other, sort=False): if sort is None: result = algos.safe_sort(result) - return self._wrap_setop_result(other, result) + return result def difference(self, other, sort=None): """