From d1794b8b2758de161249ab67cf4389aa7a2f3367 Mon Sep 17 00:00:00 2001 From: Brock Date: Sun, 15 Nov 2020 18:50:13 -0800 Subject: [PATCH] REF: Index._intersection --- pandas/core/indexes/base.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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): """