Skip to content

Commit 4f89c26

Browse files
authored
TEST: Add test for pandas-dev#22541 to ensure that error does not occur again (pandas-dev#33096)
1 parent e835b76 commit 4f89c26

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pandas/tests/groupby/test_apply.py

+14
Original file line numberDiff line numberDiff line change
@@ -866,3 +866,17 @@ def fct(group):
866866
[[1.0, 2.0], [3.0], [np.nan]], index=pd.Index(["a", "b", "none"], name="A")
867867
)
868868
tm.assert_series_equal(result, expected)
869+
870+
871+
@pytest.mark.parametrize(
872+
"function", [lambda gr: gr.index, lambda gr: gr.index + 1 - 1],
873+
)
874+
def test_apply_function_index_return(function):
875+
# GH: 22541
876+
df = pd.DataFrame([1, 2, 2, 2, 1, 2, 3, 1, 3, 1], columns=["id"])
877+
result = df.groupby("id").apply(function)
878+
expected = pd.Series(
879+
[pd.Index([0, 4, 7, 9]), pd.Index([1, 2, 3, 5]), pd.Index([6, 8])],
880+
index=pd.Index([1, 2, 3], name="id"),
881+
)
882+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)