Skip to content

Commit de98025

Browse files
author
Khor Chean Wei
authored
Update test_fillna.py (#46161)
* Update test_fillna.py * change test function name * change assert categorical equal
1 parent 24c2139 commit de98025

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

pandas/tests/series/methods/test_fillna.py

+18
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,24 @@ def test_fillna_pos_args_deprecation(self):
851851
expected = Series([1, 2, 3, 0], dtype=float)
852852
tm.assert_series_equal(result, expected)
853853

854+
@pytest.mark.parametrize(
855+
"input, input_fillna, expected_data, expected_categories",
856+
[
857+
(["A", "B", None, "A"], "B", ["A", "B", "B", "A"], ["A", "B"]),
858+
(["A", "B", np.nan, "A"], "B", ["A", "B", "B", "A"], ["A", "B"]),
859+
],
860+
)
861+
def test_fillna_categorical_accept_same_type(
862+
self, input, input_fillna, expected_data, expected_categories
863+
):
864+
# GH32414
865+
cat = Categorical(input)
866+
ser = Series(cat).fillna(input_fillna)
867+
filled = cat.fillna(ser)
868+
result = cat.fillna(filled)
869+
expected = Categorical(expected_data, categories=expected_categories)
870+
tm.assert_categorical_equal(result, expected)
871+
854872

855873
class TestFillnaPad:
856874
def test_fillna_bug(self):

0 commit comments

Comments
 (0)