Skip to content

Commit a89f7fd

Browse files
authored
Add test for gh 31605 (#31621)
1 parent d84f9eb commit a89f7fd

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pandas/tests/groupby/test_apply.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,3 +851,17 @@ 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_apply_function_returns_numpy_array():
857+
# GH 31605
858+
def fct(group):
859+
return group["B"].values.flatten()
860+
861+
df = pd.DataFrame({"A": ["a", "a", "b", "none"], "B": [1, 2, 3, np.nan]})
862+
863+
result = df.groupby("A").apply(fct)
864+
expected = pd.Series(
865+
[[1.0, 2.0], [3.0], [np.nan]], index=pd.Index(["a", "b", "none"], name="A")
866+
)
867+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)