@@ -768,12 +768,6 @@ def _assert_can_do_setop(self, other):
768768 if isinstance (other , PeriodIndex ) and self .freq != other .freq :
769769 raise raise_on_incompatible (self , other )
770770
771- def _wrap_setop_result (self , other , result ):
772- name = get_op_result_name (self , other )
773- result = self ._apply_meta (result )
774- result .name = name
775- return result
776-
777771 def intersection (self , other , sort = False ):
778772 self ._validate_sort_keyword (sort )
779773 self ._assert_can_do_setop (other )
@@ -819,6 +813,26 @@ def difference(self, other, sort=None):
819813 result = self ._shallow_copy (np .asarray (i8result , dtype = np .int64 ), name = res_name )
820814 return result
821815
816+ def _union (self , other , sort ):
817+ if not len (other ) or self .equals (other ) or not len (self ):
818+ return super ()._union (other , sort = sort )
819+
820+ # We are called by `union`, which is responsible for this validation
821+ assert isinstance (other , type (self ))
822+
823+ if not is_dtype_equal (self .dtype , other .dtype ):
824+ this = self .astype ("O" )
825+ other = other .astype ("O" )
826+ return this ._union (other , sort = sort )
827+
828+ i8self = Int64Index ._simple_new (self .asi8 )
829+ i8other = Int64Index ._simple_new (other .asi8 )
830+ i8result = i8self ._union (i8other , sort = sort )
831+
832+ res_name = get_op_result_name (self , other )
833+ result = self ._shallow_copy (np .asarray (i8result , dtype = np .int64 ), name = res_name )
834+ return result
835+
822836 # ------------------------------------------------------------------------
823837
824838 def _apply_meta (self , rawarr ):
0 commit comments