From 0074cf29c48d43dd9cf4fc88d927059267f76b1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Araujo?= Date: Sat, 19 Nov 2022 00:08:18 +0000 Subject: [PATCH 1/2] TST: Test for Dataframe.replace when column contains pd.NA (#47480) --- pandas/tests/frame/methods/test_replace.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pandas/tests/frame/methods/test_replace.py b/pandas/tests/frame/methods/test_replace.py index 626bc658b199c..65ff2040548f4 100644 --- a/pandas/tests/frame/methods/test_replace.py +++ b/pandas/tests/frame/methods/test_replace.py @@ -1503,6 +1503,15 @@ def test_replace_value_none_dtype_numeric(self, val): result = df.replace({val: None}) tm.assert_frame_equal(result, expected) + def test_replace_in_col_containing_na(self): + # GH#47480 + df = DataFrame({"A": [0, 1, 2]}) + df.at[0, "A"] = pd.NA + expected = df.copy() + df["A"].replace(to_replace=1, value=100, inplace=True) + expected.at[1, "A"] = 100 + tm.assert_frame_equal(df, expected) + class TestDataFrameReplaceRegex: @pytest.mark.parametrize( From 1f6ea85cfa61777e71035bbb0a2044d819d07de0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Araujo?= Date: Sat, 19 Nov 2022 14:00:23 +0000 Subject: [PATCH 2/2] TST: Test for Dataframe.replace when column contains pd.NA (#47480) --- pandas/tests/frame/methods/test_replace.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pandas/tests/frame/methods/test_replace.py b/pandas/tests/frame/methods/test_replace.py index 65ff2040548f4..1a1a456152592 100644 --- a/pandas/tests/frame/methods/test_replace.py +++ b/pandas/tests/frame/methods/test_replace.py @@ -1505,11 +1505,9 @@ def test_replace_value_none_dtype_numeric(self, val): def test_replace_in_col_containing_na(self): # GH#47480 - df = DataFrame({"A": [0, 1, 2]}) - df.at[0, "A"] = pd.NA - expected = df.copy() + df = DataFrame({"A": [pd.NA, 1, 2]}, dtype="Int64") df["A"].replace(to_replace=1, value=100, inplace=True) - expected.at[1, "A"] = 100 + expected = DataFrame({"A": [pd.NA, 100, 2]}, dtype="Int64") tm.assert_frame_equal(df, expected)