Skip to content

Commit c81337c

Browse files
committed
PERF: Faster comparisons of indexes when the same
1 parent ca27cca commit c81337c

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

pandas/core/indexes/base.py

+7
Original file line numberDiff line numberDiff line change
@@ -5379,6 +5379,13 @@ def _cmp_method(self, other, op):
53795379
"""
53805380
Wrapper used to dispatch comparison operations.
53815381
"""
5382+
if self.is_(other):
5383+
# short-circuit when other is same as self
5384+
if op in (operator.eq, operator.le, operator.ge):
5385+
return np.ones(self.shape, dtype=bool)
5386+
elif op in (operator.ne, operator.lt, operator.gt):
5387+
return np.zeros(self.shape, dtype=bool)
5388+
53825389
if isinstance(other, (np.ndarray, Index, ABCSeries, ExtensionArray)):
53835390
if other.ndim > 0 and len(self) != len(other):
53845391
raise ValueError("Lengths must match to compare")

0 commit comments

Comments
 (0)