@@ -768,12 +768,6 @@ def _assert_can_do_setop(self, other):
768
768
if isinstance (other , PeriodIndex ) and self .freq != other .freq :
769
769
raise raise_on_incompatible (self , other )
770
770
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
-
777
771
def intersection (self , other , sort = False ):
778
772
self ._validate_sort_keyword (sort )
779
773
self ._assert_can_do_setop (other )
@@ -819,6 +813,26 @@ def difference(self, other, sort=None):
819
813
result = self ._shallow_copy (np .asarray (i8result , dtype = np .int64 ), name = res_name )
820
814
return result
821
815
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
+
822
836
# ------------------------------------------------------------------------
823
837
824
838
def _apply_meta (self , rawarr ):
0 commit comments