@@ -142,13 +142,16 @@ def equals(self, other) -> bool:
142
142
if not isinstance (other , ABCIndexClass ):
143
143
return False
144
144
elif not isinstance (other , type (self )):
145
- try :
146
- other = type (self )(other )
147
- except (ValueError , TypeError , OverflowError ):
148
- # e.g.
149
- # ValueError -> cannot parse str entry, or OutOfBoundsDatetime
150
- # TypeError -> trying to convert IntervalIndex to DatetimeIndex
151
- # OverflowError -> Index([very_large_timedeltas])
145
+ if self ._is_convertible_to_index_for_join (other ):
146
+ try :
147
+ other = type (self )(other )
148
+ except (ValueError , TypeError , OverflowError ):
149
+ # e.g.
150
+ # ValueError -> cannot parse str entry, or OutOfBoundsDatetime
151
+ # TypeError -> trying to convert IntervalIndex to DatetimeIndex
152
+ # OverflowError -> Index([very_large_timedeltas])
153
+ return False
154
+ else :
152
155
return False
153
156
154
157
if not is_dtype_equal (self .dtype , other .dtype ):
@@ -602,6 +605,26 @@ def delete(self, loc):
602
605
arr = type (self ._data )._simple_new (new_i8s , dtype = self .dtype , freq = freq )
603
606
return type (self )._simple_new (arr , name = self .name )
604
607
608
+ @classmethod
609
+ def _is_convertible_to_index_for_join (cls , other : Index ) -> bool :
610
+ """
611
+ return a boolean whether I can attempt conversion to a
612
+ DatetimeIndex/TimedeltaIndex
613
+ """
614
+ if isinstance (other , cls ):
615
+ return False
616
+ elif len (other ) > 0 and other .inferred_type not in (
617
+ "floating" ,
618
+ "mixed-integer" ,
619
+ "integer" ,
620
+ "integer-na" ,
621
+ "mixed-integer-float" ,
622
+ "mixed" ,
623
+ "string" ,
624
+ ):
625
+ return True
626
+ return False
627
+
605
628
606
629
class DatetimeTimedeltaMixin (DatetimeIndexOpsMixin , Int64Index ):
607
630
"""
@@ -873,25 +896,6 @@ def _maybe_utc_convert(self, other):
873
896
other = other .tz_convert ("UTC" )
874
897
return this , other
875
898
876
- @classmethod
877
- def _is_convertible_to_index_for_join (cls , other : Index ) -> bool :
878
- """
879
- return a boolean whether I can attempt conversion to a
880
- DatetimeIndex/TimedeltaIndex
881
- """
882
- if isinstance (other , cls ):
883
- return False
884
- elif len (other ) > 0 and other .inferred_type not in (
885
- "floating" ,
886
- "mixed-integer" ,
887
- "integer" ,
888
- "integer-na" ,
889
- "mixed-integer-float" ,
890
- "mixed" ,
891
- ):
892
- return True
893
- return False
894
-
895
899
def _wrap_joined_index (self , joined : np .ndarray , other ):
896
900
assert other .dtype == self .dtype , (other .dtype , self .dtype )
897
901
name = get_op_result_name (self , other )
0 commit comments