From 1e59742eb0b86aefc37a6d55cc03e16fc8cf771c Mon Sep 17 00:00:00 2001 From: Thai Villaluna Date: Wed, 10 Sep 2025 00:34:04 -0700 Subject: [PATCH 1/2] add test for categorical series --- pandas/tests/frame/methods/test_fillna.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pandas/tests/frame/methods/test_fillna.py b/pandas/tests/frame/methods/test_fillna.py index 8915d6f205d65..4eee3a79c4b0e 100644 --- a/pandas/tests/frame/methods/test_fillna.py +++ b/pandas/tests/frame/methods/test_fillna.py @@ -256,6 +256,21 @@ def test_fillna_categorical_nan(self): idx = TimedeltaIndex(["1 days", "2 days", "1 days", NaT, NaT]) df = DataFrame({"a": Categorical(idx)}) tm.assert_frame_equal(df.fillna(value=NaT), df) + + def test_fillna_with_categorical_series(self): + df = DataFrame({ + 'cats': Categorical(['A', 'B', 'C']), + 'ints': [1.0, 2.0, np.nan] + }) + + filler = Series(Categorical([10.0, 20.0, 30.0])) + df.fillna({'ints': filler}, inplace=True) + + expected = DataFrame({ + 'cats': Categorical(['A', 'B', 'C']), + 'ints': [1.0, 2.0, 30.0] + }) + tm.assert_frame_equal(df, expected) def test_fillna_no_downcast(self, frame_or_series): # GH#45603 preserve object dtype From 3bc51e7b055ad2ce65f59955492a3b51c9380f45 Mon Sep 17 00:00:00 2001 From: Thai Villaluna Date: Thu, 11 Sep 2025 12:53:50 -0500 Subject: [PATCH 2/2] fix formatting --- pandas/tests/frame/methods/test_fillna.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/pandas/tests/frame/methods/test_fillna.py b/pandas/tests/frame/methods/test_fillna.py index 4eee3a79c4b0e..0868fcf573918 100644 --- a/pandas/tests/frame/methods/test_fillna.py +++ b/pandas/tests/frame/methods/test_fillna.py @@ -256,20 +256,18 @@ def test_fillna_categorical_nan(self): idx = TimedeltaIndex(["1 days", "2 days", "1 days", NaT, NaT]) df = DataFrame({"a": Categorical(idx)}) tm.assert_frame_equal(df.fillna(value=NaT), df) - + def test_fillna_with_categorical_series(self): - df = DataFrame({ - 'cats': Categorical(['A', 'B', 'C']), - 'ints': [1.0, 2.0, np.nan] - }) - + df = DataFrame( + {"cats": Categorical(["A", "B", "C"]), "ints": [1.0, 2.0, np.nan]} + ) + filler = Series(Categorical([10.0, 20.0, 30.0])) - df.fillna({'ints': filler}, inplace=True) - - expected = DataFrame({ - 'cats': Categorical(['A', 'B', 'C']), - 'ints': [1.0, 2.0, 30.0] - }) + df.fillna({"ints": filler}, inplace=True) + + expected = DataFrame( + {"cats": Categorical(["A", "B", "C"]), "ints": [1.0, 2.0, 30.0]} + ) tm.assert_frame_equal(df, expected) def test_fillna_no_downcast(self, frame_or_series):