@@ -988,7 +988,7 @@ def f(m, v, i):
988
988
989
989
return [self .make_block (new_values , fastpath = True )]
990
990
991
- def coerce_to_target_dtype (self , other ):
991
+ def coerce_to_target_dtype (self , other , copy = False ):
992
992
"""
993
993
coerce the current block to a dtype compat for other
994
994
we will return a block, possibly object, and not raise
@@ -1005,7 +1005,7 @@ def coerce_to_target_dtype(self, other):
1005
1005
1006
1006
if self .is_bool or is_object_dtype (dtype ) or is_bool_dtype (dtype ):
1007
1007
# we don't upcast to bool
1008
- return self .astype (object )
1008
+ return self .astype (object , copy = copy )
1009
1009
1010
1010
elif ((self .is_float or self .is_complex ) and
1011
1011
(is_integer_dtype (dtype ) or is_float_dtype (dtype ))):
@@ -1019,14 +1019,14 @@ def coerce_to_target_dtype(self, other):
1019
1019
# not a datetime
1020
1020
if not ((is_datetime64_dtype (dtype ) or
1021
1021
is_datetime64tz_dtype (dtype )) and self .is_datetime ):
1022
- return self .astype (object )
1022
+ return self .astype (object , copy = copy )
1023
1023
1024
1024
# don't upcast timezone with different timezone or no timezone
1025
1025
mytz = getattr (self .dtype , 'tz' , None )
1026
1026
othertz = getattr (dtype , 'tz' , None )
1027
1027
1028
1028
if str (mytz ) != str (othertz ):
1029
- return self .astype (object )
1029
+ return self .astype (object , copy = copy )
1030
1030
1031
1031
raise AssertionError ("possible recursion in "
1032
1032
"coerce_to_target_dtype: {} {}" .format (
@@ -1036,18 +1036,18 @@ def coerce_to_target_dtype(self, other):
1036
1036
1037
1037
# not a timedelta
1038
1038
if not (is_timedelta64_dtype (dtype ) and self .is_timedelta ):
1039
- return self .astype (object )
1039
+ return self .astype (object , copy = copy )
1040
1040
1041
1041
raise AssertionError ("possible recursion in "
1042
1042
"coerce_to_target_dtype: {} {}" .format (
1043
1043
self , other ))
1044
1044
1045
1045
try :
1046
- return self .astype (dtype )
1046
+ return self .astype (dtype , copy = copy )
1047
1047
except (ValueError , TypeError ):
1048
1048
pass
1049
1049
1050
- return self .astype (object )
1050
+ return self .astype (object , copy = copy )
1051
1051
1052
1052
def interpolate (self , method = 'pad' , axis = 0 , index = None , values = None ,
1053
1053
inplace = False , limit = None , limit_direction = 'forward' ,
@@ -2636,6 +2636,9 @@ class SparseBlock(NonConsolidatableMixIn, Block):
2636
2636
_ftype = 'sparse'
2637
2637
_holder = SparseArray
2638
2638
2639
+ def coerce_to_target_dtype (self , other , copy = True ):
2640
+ return super (SparseBlock , self ).coerce_to_target_dtype (other , copy )
2641
+
2639
2642
@property
2640
2643
def shape (self ):
2641
2644
return (len (self .mgr_locs ), self .sp_index .length )
0 commit comments