@@ -4870,14 +4870,24 @@ def combine(self, other, func, fill_value=None, overwrite=True):
4870
4870
series [this_mask ] = fill_value
4871
4871
otherSeries [other_mask ] = fill_value
4872
4872
4873
- # if we have different dtypes, possibly promote
4874
- new_dtype = this_dtype
4875
- if not is_dtype_equal ( this_dtype , other_dtype ):
4876
- new_dtype = find_common_type ([ this_dtype , other_dtype ])
4877
- if not is_dtype_equal ( this_dtype , new_dtype ) :
4873
+ if col not in self . columns :
4874
+ # If self DataFrame does not have col in other DataFrame,
4875
+ # try to promote series, which is all NaN, as other_dtype.
4876
+ new_dtype = other_dtype
4877
+ try :
4878
4878
series = series .astype (new_dtype )
4879
- if not is_dtype_equal (other_dtype , new_dtype ):
4880
- otherSeries = otherSeries .astype (new_dtype )
4879
+ except ValueError :
4880
+ # e.g. new_dtype is integer types
4881
+ pass
4882
+ else :
4883
+ # if we have different dtypes, possibly promote
4884
+ new_dtype = this_dtype
4885
+ if not is_dtype_equal (this_dtype , other_dtype ):
4886
+ new_dtype = find_common_type ([this_dtype , other_dtype ])
4887
+ if not is_dtype_equal (this_dtype , new_dtype ):
4888
+ series = series .astype (new_dtype )
4889
+ if not is_dtype_equal (other_dtype , new_dtype ):
4890
+ otherSeries = otherSeries .astype (new_dtype )
4881
4891
4882
4892
# see if we need to be represented as i8 (datetimelike)
4883
4893
# try to keep us at this dtype
@@ -4950,6 +4960,11 @@ def combiner(x, y, needs_i8_conversion=False):
4950
4960
else :
4951
4961
mask = isna (x_values )
4952
4962
4963
+ # If the column y in other DataFrame is not in first DataFrame,
4964
+ # just return y_values.
4965
+ if y .name not in self .columns :
4966
+ return y_values
4967
+
4953
4968
return expressions .where (mask , y_values , x_values )
4954
4969
4955
4970
return self .combine (other , combiner , overwrite = False )
0 commit comments