@@ -138,13 +138,16 @@ def equals(self, other) -> bool:
138
138
if not isinstance (other , ABCIndexClass ):
139
139
return False
140
140
elif not isinstance (other , type (self )):
141
- try :
142
- other = type (self )(other )
143
- except (ValueError , TypeError , OverflowError ):
144
- # e.g.
145
- # ValueError -> cannot parse str entry, or OutOfBoundsDatetime
146
- # TypeError -> trying to convert IntervalIndex to DatetimeIndex
147
- # OverflowError -> Index([very_large_timedeltas])
141
+ if self ._is_convertible_to_index_for_join (other ):
142
+ try :
143
+ other = type (self )(other )
144
+ except (ValueError , TypeError , OverflowError ):
145
+ # e.g.
146
+ # ValueError -> cannot parse str entry, or OutOfBoundsDatetime
147
+ # TypeError -> trying to convert IntervalIndex to DatetimeIndex
148
+ # OverflowError -> Index([very_large_timedeltas])
149
+ return False
150
+ else :
148
151
return False
149
152
150
153
if not is_dtype_equal (self .dtype , other .dtype ):
@@ -596,6 +599,26 @@ def _convert_arr_indexer(self, keyarr):
596
599
converted_arr = com .asarray_tuplesafe (keyarr )
597
600
return converted_arr
598
601
602
+ @classmethod
603
+ def _is_convertible_to_index_for_join (cls , other : Index ) -> bool :
604
+ """
605
+ return a boolean whether I can attempt conversion to a
606
+ DatetimeIndex/TimedeltaIndex
607
+ """
608
+ if isinstance (other , cls ):
609
+ return False
610
+ elif len (other ) > 0 and other .inferred_type not in (
611
+ "floating" ,
612
+ "mixed-integer" ,
613
+ "integer" ,
614
+ "integer-na" ,
615
+ "mixed-integer-float" ,
616
+ "mixed" ,
617
+ "string" ,
618
+ ):
619
+ return True
620
+ return False
621
+
599
622
600
623
class DatetimeTimedeltaMixin (DatetimeIndexOpsMixin , Int64Index ):
601
624
"""
@@ -903,6 +926,15 @@ def _is_convertible_to_index_for_join(cls, other: Index) -> bool:
903
926
return True
904
927
return False
905
928
929
+ def _wrap_joined_index (self , joined : np .ndarray , other ):
930
+ assert other .dtype == self .dtype , (other .dtype , self .dtype )
931
+ name = get_op_result_name (self , other )
932
+
933
+ freq = self .freq if self ._can_fast_union (other ) else None
934
+ new_data = type (self ._data )._simple_new (joined , dtype = self .dtype , freq = freq )
935
+
936
+ return type (self )._simple_new (new_data , name = name )
937
+
906
938
# --------------------------------------------------------------------
907
939
# List-Like Methods
908
940
0 commit comments