@@ -3143,7 +3143,7 @@ def combine_first(self, other):
3143
3143
combiner = lambda x , y : np .where (isnull (x ), y , x )
3144
3144
return self .combine (other , combiner )
3145
3145
3146
- def update (self , other , join = 'left' , overwrite = True ):
3146
+ def update (self , other , join = 'left' , overwrite = True , filter_func = None ):
3147
3147
"""
3148
3148
Modify DataFrame in place using non-NA values from passed
3149
3149
DataFrame. Aligns on indices
@@ -3153,8 +3153,10 @@ def update(self, other, join='left', overwrite=True):
3153
3153
other : DataFrame
3154
3154
join : {'left', 'right', 'outer', 'inner'}, default 'left'
3155
3155
overwrite : boolean, default True
3156
- If True then overwrite values for common keys in the calling
3157
- frame
3156
+ If True then overwrite values for common keys in the calling frame
3157
+ filter_func : callable(1d-array) -> 1d-array<boolean>, default None
3158
+ Can choose to replace values other than NA. Return True for values
3159
+ that should be updated
3158
3160
"""
3159
3161
if join != 'left' :
3160
3162
raise NotImplementedError
@@ -3163,10 +3165,13 @@ def update(self, other, join='left', overwrite=True):
3163
3165
for col in self .columns :
3164
3166
this = self [col ].values
3165
3167
that = other [col ].values
3166
- if overwrite :
3167
- mask = isnull (that )
3168
+ if filter_func is not None :
3169
+ mask = - filter_func ( this ) | isnull (that )
3168
3170
else :
3169
- mask = notnull (this )
3171
+ if overwrite :
3172
+ mask = isnull (that )
3173
+ else :
3174
+ mask = notnull (this )
3170
3175
self [col ] = np .where (mask , this , that )
3171
3176
3172
3177
#----------------------------------------------------------------------
0 commit comments