Skip to content

Commit db83ead

Browse files
committed
PERF: Faster comparisons of indexes when the same
1 parent c0c3516 commit db83ead

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
@@ -5363,6 +5363,13 @@ def _cmp_method(self, other, op):
53635363
"""
53645364
Wrapper used to dispatch comparison operations.
53655365
"""
5366+
if self.is_(other):
5367+
# short-circuit when other is same as self
5368+
if op in (operator.eq, operator.le, operator.ge):
5369+
return np.ones(self.shape, dtype=bool)
5370+
elif op in (operator.ne, operator.lt, operator.gt):
5371+
return np.zeros(self.shape, dtype=bool)
5372+
53665373
if isinstance(other, (np.ndarray, Index, ABCSeries, ExtensionArray)):
53675374
if len(self) != len(other):
53685375
raise ValueError("Lengths must match to compare")

0 commit comments

Comments
 (0)