@@ -3723,7 +3723,7 @@ def _compare(a, b):
3723
3723
return self ._constructor (data = new_data , index = self .index ,
3724
3724
columns = self .columns , copy = False )
3725
3725
3726
- def combine (self , other , func , fill_value = None ):
3726
+ def combine (self , other , func , fill_value = None , overwrite = True ):
3727
3727
"""
3728
3728
Add two DataFrame objects and do not propagate NaN values, so if for a
3729
3729
(column, time) one frame is missing a value, it will default to the
@@ -3734,6 +3734,8 @@ def combine(self, other, func, fill_value=None):
3734
3734
other : DataFrame
3735
3735
func : function
3736
3736
fill_value : scalar value
3737
+ overwrite : boolean, default True
3738
+ If True then overwrite values for common keys in the calling frame
3737
3739
3738
3740
Returns
3739
3741
-------
@@ -3760,9 +3762,16 @@ def combine(self, other, func, fill_value=None):
3760
3762
series = this [col ].values
3761
3763
otherSeries = other [col ].values
3762
3764
3765
+ this_mask = isnull (series )
3766
+ other_mask = isnull (otherSeries )
3767
+
3768
+ # don't overwrite columns unecessarily
3769
+ # DO propogate if this column is not in the intersection
3770
+ if not overwrite and other_mask .all ():
3771
+ result [col ] = this [col ].copy ()
3772
+ continue
3773
+
3763
3774
if do_fill :
3764
- this_mask = isnull (series )
3765
- other_mask = isnull (otherSeries )
3766
3775
series = series .copy ()
3767
3776
otherSeries = otherSeries .copy ()
3768
3777
series [this_mask ] = fill_value
@@ -3798,7 +3807,7 @@ def combine_first(self, other):
3798
3807
combined : DataFrame
3799
3808
"""
3800
3809
combiner = lambda x , y : np .where (isnull (x ), y , x )
3801
- return self .combine (other , combiner )
3810
+ return self .combine (other , combiner , overwrite = False )
3802
3811
3803
3812
def update (self , other , join = 'left' , overwrite = True , filter_func = None ,
3804
3813
raise_conflict = False ):
0 commit comments