Skip to content

Commit 20433be

Browse files
authored
TST: added groupby apply test for nan coerce (#44038)
1 parent 0f678a9 commit 20433be

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

pandas/tests/groupby/test_apply.py

+21
Original file line numberDiff line numberDiff line change
@@ -1157,3 +1157,24 @@ def test_apply_na(dropna):
11571157
result = dfgrp.apply(lambda grp_df: grp_df.nlargest(1, "z"))
11581158
expected = dfgrp.apply(lambda x: x.sort_values("z", ascending=False).head(1))
11591159
tm.assert_frame_equal(result, expected)
1160+
1161+
1162+
def test_apply_empty_string_nan_coerce_bug():
1163+
# GH#24903
1164+
result = (
1165+
DataFrame(
1166+
{
1167+
"a": [1, 1, 2, 2],
1168+
"b": ["", "", "", ""],
1169+
"c": pd.to_datetime([1, 2, 3, 4], unit="s"),
1170+
}
1171+
)
1172+
.groupby(["a", "b"])
1173+
.apply(lambda df: df.iloc[-1])
1174+
)
1175+
expected = DataFrame(
1176+
[[1, "", pd.to_datetime(2, unit="s")], [2, "", pd.to_datetime(4, unit="s")]],
1177+
columns=["a", "b", "c"],
1178+
index=MultiIndex.from_tuples([(1, ""), (2, "")], names=["a", "b"]),
1179+
)
1180+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)