Skip to content

Commit 254ffdf

Browse files
committed
Add tests for transform fillna
1 parent ef40b6d commit 254ffdf

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

pandas/tests/groupby/test_transform.py

+24
Original file line numberDiff line numberDiff line change
@@ -1196,3 +1196,27 @@ def test_transform_lambda_indexing():
11961196
),
11971197
)
11981198
tm.assert_frame_equal(result, expected)
1199+
1200+
1201+
@pytest.mark.parametrize(
1202+
"input_df",
1203+
[
1204+
DataFrame(
1205+
{
1206+
"A": [121, 121, 121, 121, 231, 231, 676],
1207+
"B": [1, 2, np.nan, 3, 3, np.nan, 4],
1208+
}
1209+
),
1210+
DataFrame(
1211+
{
1212+
"A": [121, 121, 121, 121, 231, 231, 676],
1213+
"B": [1.0, 2.0, 2.0, 3.0, 3.0, 3.0, 4.0],
1214+
}
1215+
),
1216+
],
1217+
)
1218+
def test_groupby_transform_fillna(input_df):
1219+
# GH 27905
1220+
result = input_df.groupby("A").transform(lambda x: x.fillna(x.mean()))
1221+
expected = pd.DataFrame({"B": [1.0, 2.0, 2.0, 3.0, 3.0, 3.0, 4.0]})
1222+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)