diff --git a/pandas/tests/series/methods/test_fillna.py b/pandas/tests/series/methods/test_fillna.py index 03e126587ce1a..4aaaea12b393d 100644 --- a/pandas/tests/series/methods/test_fillna.py +++ b/pandas/tests/series/methods/test_fillna.py @@ -7,6 +7,7 @@ import numpy as np import pytest import pytz +from typing_extensions import Literal from pandas import ( Categorical, @@ -671,6 +672,27 @@ def test_fillna_categorical_with_new_categories(self, fill_value, expected_outpu result = ser.fillna(fill_value) tm.assert_series_equal(result, exp) + @pytest.mark.parametrize( + "fill_value, expected_output", + [ + ("B", ["A", "B", "B", "B", "C"]), + ("C", ["A", "B", "C", "C", "C"]) + ], + ) + + def test_fillna_categorical(self, fill_value, expected_output): + # GH32414 + data = ["A", "B", np.nan, np.nan, "C"] + cat = Categorical(data, categories=["A", "B", "C"]) + ser = Series(cat) + exp_cat = Categorical(expected_output, categories=["A", "B", "C"]) + exp_ser = Series(exp_cat) + result_ser = ser.fillna(fill_value) + filled = cat.fillna(fill_value) + tm.assert_almost_equal(result_ser, exp_ser) + tm.assert_almost_equal(filled, exp_cat) + + def test_fillna_categorical_raises(self): data = ["a", np.nan, "b", np.nan, np.nan] ser = Series(Categorical(data, categories=["a", "b"]))