Skip to content

Commit ee999f7

Browse files
committed
BUG: handle nan values in DataFrame.update when overwrite=False (#15593)
BUG: handle nan values in DataFrame.update when overwrite=False (#15593) add nan test for DataFrame.update update whatsnew v0.20.2
1 parent 49ec31b commit ee999f7

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

doc/source/whatsnew/v0.20.2.txt

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Bug Fixes
3737
~~~~~~~~~
3838

3939
- Bug in using ``pathlib.Path`` or ``py.path.local`` objects with io functions (:issue:`16291`)
40+
- Bug in using ``DataFrame.update`` when overwrite=False and the second value is nan
4041

4142
Conversion
4243
^^^^^^^^^^

pandas/core/frame.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -3921,13 +3921,13 @@ def update(self, other, join='left', overwrite=True, filter_func=None,
39213921

39223922
if overwrite:
39233923
mask = isnull(that)
3924-
3925-
# don't overwrite columns unecessarily
3926-
if mask.all():
3927-
continue
39283924
else:
39293925
mask = notnull(this)
39303926

3927+
# don't overwrite columns unecessarily
3928+
if mask.all():
3929+
continue
3930+
39313931
self[col] = expressions.where(mask, this, that,
39323932
raise_on_error=True)
39333933

pandas/tests/frame/test_combine_concat.py

+10
Original file line numberDiff line numberDiff line change
@@ -763,3 +763,13 @@ def test_concat_datetime_datetime64_frame(self):
763763

764764
# it works!
765765
pd.concat([df1, df2_obj])
766+
767+
768+
class TestDataFrameUpdate(TestData):
769+
770+
def test_update_nan(self):
771+
# #15593 #15617
772+
df1 = DataFrame({'A': [1, None, 3], 'B': date_range('2000', periods=3)})
773+
df2 = DataFrame({'A': [None, 2, 3]})
774+
df1.update(df2, overwrite=False)
775+
# it works!

0 commit comments

Comments
 (0)