diff --git a/pandas/tests/groupby/test_missing.py b/pandas/tests/groupby/test_missing.py index e53518269408a..f3149abb52291 100644 --- a/pandas/tests/groupby/test_missing.py +++ b/pandas/tests/groupby/test_missing.py @@ -43,6 +43,18 @@ def test_ffill_missing_arguments(): df.groupby("b").fillna() +@pytest.mark.parametrize( + "method, expected", [("ffill", [None, "a", "a"]), ("bfill", ["a", "a", None])] +) +def test_fillna_with_string_dtype(method, expected): + # GH 40250 + df = DataFrame({"a": pd.array([None, "a", None], dtype="string"), "b": [0, 0, 0]}) + grp = df.groupby("b") + result = grp.fillna(method=method) + expected = DataFrame({"a": pd.array(expected, dtype="string")}) + tm.assert_frame_equal(result, expected) + + def test_fill_consistency(): # GH9221