Skip to content

Commit f34a65b

Browse files
TST: group by - apply Key Error (#44806)
* Test for Group By - Apply Key Error * Paramaters change
1 parent 3ea4638 commit f34a65b

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

pandas/tests/groupby/test_apply.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,3 +1177,25 @@ def test_apply_empty_string_nan_coerce_bug():
11771177
index=MultiIndex.from_tuples([(1, ""), (2, "")], names=["a", "b"]),
11781178
)
11791179
tm.assert_frame_equal(result, expected)
1180+
1181+
1182+
@pytest.mark.parametrize("index_values", [[1, 2, 3], [1.0, 2.0, 3.0]])
1183+
def test_apply_index_key_error_bug(index_values):
1184+
# GH 44310
1185+
result = DataFrame(
1186+
{
1187+
"a": ["aa", "a2", "a3"],
1188+
"b": [1, 2, 3],
1189+
},
1190+
index=Index(index_values),
1191+
)
1192+
expected = DataFrame(
1193+
{
1194+
"b_mean": [2.0, 3.0, 1.0],
1195+
},
1196+
index=Index(["a2", "a3", "aa"], name="a"),
1197+
)
1198+
result = result.groupby("a").apply(
1199+
lambda df: Series([df["b"].mean()], index=["b_mean"])
1200+
)
1201+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)