8000 TEST: Add test for #22541 to ensure that error does not occur again · phofl/pandas@5a381c3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5a381c3

Browse files
phoflpatrick
authored andcommitted
TEST: Add test for pandas-dev#22541 to ensure that error does not occur again
1 parent e88c392 commit 5a381c3

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

pandas/tests/groupby/test_apply.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,3 +866,16 @@ 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+
def test_apply_function_index_return():
872+
# GH: 22541
873+
df = pd.DataFrame([1, 2, 2, 2, 1, 2, 3, 1, 3, 1], columns=["id"])
874+
result = df.groupby("id").apply(lambda gr: gr.index)
875+
result_2 = df.groupby("id").apply(lambda gr: gr.index + 1 - 1)
876+
expected = pd.Series(
877+
[pd.Index([0, 4, 7, 9]), pd.Index([1, 2, 3, 5]), pd.Index([6, 8])],
878+
index=pd.Index([1, 2, 3], name="id"),
879+
)
880+
tm.assert_series_equal(result, expected)
881+
tm.assert_series_equal(result, result_2)

0 commit comments

Comments
 (0)
0