From 2bfbc6995fc583d46c2c5ce52c1e1306341d5d5d Mon Sep 17 00:00:00 2001 From: jfegg Date: Wed, 19 Nov 2025 23:54:41 -0500 Subject: [PATCH 1/3] Test added for preserve mixed dtypes on update --- pandas/tests/frame/methods/test_update.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pandas/tests/frame/methods/test_update.py b/pandas/tests/frame/methods/test_update.py index f91238104ec89..5fe9d2789bfcc 100644 --- a/pandas/tests/frame/methods/test_update.py +++ b/pandas/tests/frame/methods/test_update.py @@ -228,3 +228,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 = pd.DataFrame({"a": [1, 2, 3], "b": ["x", "y", "z"]}) + df = df.astype({"a": dtype1, "b": dtype2}) + + other = pd.DataFrame({"a": [4, 5], "b": ["a", "b"]}) + other = other.astype({"a": dtype1, "b": dtype2}) + + expected = pd.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) From 5618104e4e4f0a510f25d76ee648414b7fef4365 Mon Sep 17 00:00:00 2001 From: jfegg Date: Thu, 20 Nov 2025 13:44:24 -0500 Subject: [PATCH 2/3] Fixed namespace issue --- pandas/tests/frame/methods/test_update.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/tests/frame/methods/test_update.py b/pandas/tests/frame/methods/test_update.py index 5fe9d2789bfcc..6e1594f111f30 100644 --- a/pandas/tests/frame/methods/test_update.py +++ b/pandas/tests/frame/methods/test_update.py @@ -233,13 +233,13 @@ def test_update_preserve_mixed_dtypes(self): # GH#44104 dtype1 = pd.Int64Dtype() dtype2 = pd.StringDtype() - df = pd.DataFrame({"a": [1, 2, 3], "b": ["x", "y", "z"]}) + df = DataFrame({"a": [1, 2, 3], "b": ["x", "y", "z"]}) df = df.astype({"a": dtype1, "b": dtype2}) - other = pd.DataFrame({"a": [4, 5], "b": ["a", "b"]}) + other = DataFrame({"a": [4, 5], "b": ["a", "b"]}) other = other.astype({"a": dtype1, "b": dtype2}) - expected = pd.DataFrame({"a": [4, 5, 3], "b": ["a", "b", "z"]}) + expected = DataFrame({"a": [4, 5, 3], "b": ["a", "b", "z"]}) expected = expected.astype({"a": dtype1, "b": dtype2}) df.update(other) From 18c2b53f919b38919c4b76e2866a87ff1af1a9fe Mon Sep 17 00:00:00 2001 From: jfegg Date: Thu, 20 Nov 2025 16:59:34 -0500 Subject: [PATCH 3/3] Add Int64 test to original update test --- pandas/tests/frame/methods/test_update.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/tests/frame/methods/test_update.py b/pandas/tests/frame/methods/test_update.py index 6e1594f111f30..81b25c0ad982e 100644 --- a/pandas/tests/frame/methods/test_update.py +++ b/pandas/tests/frame/methods/test_update.py @@ -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):