@@ -5072,14 +5072,24 @@ def combine(self, other, func, fill_value=None, overwrite=True):
5072
5072
series [this_mask ] = fill_value
5073
5073
otherSeries [other_mask ] = fill_value
5074
5074
5075
- # if we have different dtypes, possibly promote
5076
- new_dtype = this_dtype
5077
- if not is_dtype_equal ( this_dtype , other_dtype ):
5078
- new_dtype = find_common_type ([ this_dtype , other_dtype ])
5079
- if not is_dtype_equal ( this_dtype , new_dtype ) :
5075
+ if col not in self . columns :
5076
+ # If self DataFrame does not have col in other DataFrame,
5077
+ # try to promote series, which is all NaN, as other_dtype.
5078
+ new_dtype = other_dtype
5079
+ try :
5080
5080
series = series .astype (new_dtype )
5081
- if not is_dtype_equal (other_dtype , new_dtype ):
5082
- otherSeries = otherSeries .astype (new_dtype )
5081
+ except ValueError :
5082
+ # e.g. new_dtype is integer types
5083
+ pass
5084
+ else :
5085
+ # if we have different dtypes, possibly promote
5086
+ new_dtype = this_dtype
5087
+ if not is_dtype_equal (this_dtype , other_dtype ):
5088
+ new_dtype = find_common_type ([this_dtype , other_dtype ])
5089
+ if not is_dtype_equal (this_dtype , new_dtype ):
5090
+ series = series .astype (new_dtype )
5091
+ if not is_dtype_equal (other_dtype , new_dtype ):
5092
+ otherSeries = otherSeries .astype (new_dtype )
5083
5093
5084
5094
# see if we need to be represented as i8 (datetimelike)
5085
5095
# try to keep us at this dtype
@@ -5153,6 +5163,11 @@ def combiner(x, y, needs_i8_conversion=False):
5153
5163
else :
5154
5164
mask = isna (x_values )
5155
5165
5166
+ # If the column y in other DataFrame is not in first DataFrame,
5167
+ # just return y_values.
5168
+ if y .name not in self .columns :
5169
+ return y_values
5170
+
5156
5171
return expressions .where (mask , y_values , x_values )
5157
5172
5158
5173
return self .combine (other , combiner , overwrite = False )
0 commit comments