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