From 8526d1b6027a33ae8299e7dee6445a6a7c041c66 Mon Sep 17 00:00:00 2001 From: Christopher Whelan Date: Sat, 20 Jul 2019 02:11:11 -0700 Subject: [PATCH] PERF: speed up IntervalIndex._intersection_non_unique by ~50x --- pandas/core/indexes/interval.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/pandas/core/indexes/interval.py b/pandas/core/indexes/interval.py index 561cf436c9af4..7372dada3b48a 100644 --- a/pandas/core/indexes/interval.py +++ b/pandas/core/indexes/interval.py @@ -1250,15 +1250,9 @@ def _intersection_non_unique(self, other: "IntervalIndex") -> "IntervalIndex": first_nan_loc = np.arange(len(self))[self.isna()][0] mask[first_nan_loc] = True - lmiss = other.left.get_indexer_non_unique(self.left)[1] - lmatch = np.setdiff1d(np.arange(len(self)), lmiss) - - for i in lmatch: - potential = other.left.get_loc(self.left[i]) - if is_scalar(potential): - if self.right[i] == other.right[potential]: - mask[i] = True - elif self.right[i] in other.right[potential]: + other_tups = set(zip(other.left, other.right)) + for i, tup in enumerate(zip(self.left, self.right)): + if tup in other_tups: mask[i] = True return self[mask]