Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.20.2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Bug Fixes
~~~~~~~~~

- Bug in using ``pathlib.Path`` or ``py.path.local`` objects with io functions (:issue:`16291`)
- Bug in ``DataFrame.update()`` with ``overwrite=False`` and ``NaN values`` (:issue:`15593`)

Conversion
^^^^^^^^^^
Expand Down
8 changes: 4 additions & 4 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -3921,13 +3921,13 @@ def update(self, other, join='left', overwrite=True, filter_func=None,

if overwrite:
mask = isnull(that)

# don't overwrite columns unecessarily
if mask.all():
continue
else:
mask = notnull(this)

# don't overwrite columns unecessarily
if mask.all():
continue

self[col] = expressions.where(mask, this, that,
raise_on_error=True)

Expand Down
22 changes: 22 additions & 0 deletions pandas/tests/frame/test_combine_concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,3 +763,25 @@ def test_concat_datetime_datetime64_frame(self):

# it works!
pd.concat([df1, df2_obj])


class TestDataFrameUpdate(TestData):

def test_update_nan(self):
# #15593 #15617
# test 1
df1 = DataFrame({'A': [1.0, 2, 3], 'B': date_range('2000', periods=3)})
df2 = DataFrame({'A': [None, 2, 3]})
expected = df1.copy()
df1.update(df2, overwrite=False)

tm.assert_frame_equal(df1, expected)

# test 2
df1 = DataFrame({'A': [1.0, None, 3], 'B': date_range('2000', periods=3)})
df2 = DataFrame({'A': [None, 2, 3]})
expected = DataFrame({'A': [1.0, 2, 3], 'B': date_range('2000', periods=3)})
df1.update(df2, overwrite=False)

tm.assert_frame_equal(df1, expected)