Skip to content

Commit e22cf83

Browse files
qwhelanquintusdias
authored andcommitted
PERF: speed up IntervalIndex._intersection_non_unique by ~50x (pandas-dev#27489)
1 parent 5731540 commit e22cf83

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

pandas/core/indexes/interval.py

+3-9
Original file line numberDiff line numberDiff line change
@@ -1250,15 +1250,9 @@ def _intersection_non_unique(self, other: "IntervalIndex") -> "IntervalIndex":
12501250
first_nan_loc = np.arange(len(self))[self.isna()][0]
12511251
mask[first_nan_loc] = True
12521252

1253-
lmiss = other.left.get_indexer_non_unique(self.left)[1]
1254-
lmatch = np.setdiff1d(np.arange(len(self)), lmiss)
1255-
1256-
for i in lmatch:
1257-
potential = other.left.get_loc(self.left[i])
1258-
if is_scalar(potential):
1259-
if self.right[i] == other.right[potential]:
1260-
mask[i] = True
1261-
elif self.right[i] in other.right[potential]:
1253+
other_tups = set(zip(other.left, other.right))
1254+
for i, tup in enumerate(zip(self.left, self.right)):
1255+
if tup in other_tups:
12621256
mask[i] = True
12631257

12641258
return self[mask]

0 commit comments

Comments
 (0)