@@ -5363,6 +5363,24 @@ def _cmp_method(self, other, op):
5363
5363
"""
5364
5364
Wrapper used to dispatch comparison operations.
5365
5365
"""
5366
+ from .multi import MultiIndex
5367
+
5368
+ if self .is_ (other ) and not isinstance (self , MultiIndex ):
5369
+ # short-circuit when other is same as self
5370
+ # if we're comparing equality, return an np.ones array, else an np.zeros arr
5371
+ bool_arr_type , na_bool = {
5372
+ operator .eq : (np .ones , False ),
5373
+ operator .le : (np .ones , False ),
5374
+ operator .ge : (np .ones , False ),
5375
+ operator .ne : (np .zeros , True ),
5376
+ operator .lt : (np .zeros , True ),
5377
+ operator .gt : (np .zeros , True ),
5378
+ }[op ]
5379
+ bool_arr = bool_arr_type (self .shape , dtype = bool )
5380
+ if self ._can_hold_na :
5381
+ bool_arr [isna (self )] = na_bool
5382
+ return bool_arr
5383
+
5366
5384
if isinstance (other , (np .ndarray , Index , ABCSeries , ExtensionArray )):
5367
5385
if len (self ) != len (other ):
5368
5386
raise ValueError ("Lengths must match to compare" )
0 commit comments