Skip to content

Commit 8c23c63

Browse files
committed
Add test for gh 31605
1 parent c815ffa commit 8c23c63

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
@@ -851,3 +851,16 @@ def test_apply_function_returns_non_pandas_non_scalar(function, expected_values)
851851
result = df.groupby("groups").apply(function)
852852
expected = pd.Series(expected_values, index=pd.Index(["A", "B"], name="groups"))
853853
tm.assert_series_equal(result, expected)
854+
855+
856+
def test_type_error_complex_index_non_scalar_return():
857+
# GH 31605
858+
def fct(group):
859+
return group[1].values.flatten()
860+
861+
df = pd.DataFrame([("A", 1), ("A", 2), ("A", 3), ("B", 4), ("B", 5), ("C", np.nan)])
862+
result = df.groupby(0).apply(fct)
863+
expected = pd.Series(
864+
[[1.0, 2.0, 3.0], [4.0, 5.0], [np.nan]], index=pd.Index(list("ABC"), name=0)
865+
)
866+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)