Skip to content
Open
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
17 changes: 17 additions & 0 deletions pandas/tests/frame/methods/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ def test_update_dt_column_with_NaT_create_column(self):
np.datetime64("2000-01-02T00:00:00"),
np.dtype("datetime64[ns]"),
),
(1, 2, pd.Int64Dtype()),
],
)
def test_update_preserve_dtype(self, value_df, value_other, dtype):
Expand Down Expand Up @@ -228,3 +229,19 @@ def test_update_on_duplicate_frame_unique_argument_index(self):
expected = DataFrame({"a": [2, 2, 3]}, index=[1, 1, 2], dtype=np.dtype("intc"))
df.update(other)
tm.assert_frame_equal(df, expected)

def test_update_preserve_mixed_dtypes(self):
# GH#44104
dtype1 = pd.Int64Dtype()
dtype2 = pd.StringDtype()
df = DataFrame({"a": [1, 2, 3], "b": ["x", "y", "z"]})
df = df.astype({"a": dtype1, "b": dtype2})

other = DataFrame({"a": [4, 5], "b": ["a", "b"]})
other = other.astype({"a": dtype1, "b": dtype2})

expected = DataFrame({"a": [4, 5, 3], "b": ["a", "b", "z"]})
expected = expected.astype({"a": dtype1, "b": dtype2})

df.update(other)
tm.assert_frame_equal(df, expected)
Loading