Skip to content

Commit 37e6239

Browse files
TST: Test aggregate with list values #25581 (#47559)
* TST: Test aggregate with list values #25581 * TST: Fixed PEP 8 warnings #25581 * TST: Fixed Flake8 Error #25581 * TST: Added more test cases #25581 * TST: Changed broken test to xfail #25581 Co-authored-by: Steven Rotondo <[email protected]>
1 parent 67e8c4c commit 37e6239

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

pandas/tests/groupby/aggregate/test_aggregate.py

+25
Original file line numberDiff line numberDiff line change
@@ -1413,3 +1413,28 @@ def test_multi_axis_1_raises(func):
14131413
gb = df.groupby("a", axis=1)
14141414
with pytest.raises(NotImplementedError, match="axis other than 0 is not supported"):
14151415
gb.agg(func)
1416+
1417+
1418+
@pytest.mark.parametrize(
1419+
"test, constant",
1420+
[
1421+
([[20, "A"], [20, "B"], [10, "C"]], {0: [10, 20], 1: ["C", ["A", "B"]]}),
1422+
([[20, "A"], [20, "B"], [30, "C"]], {0: [20, 30], 1: [["A", "B"], "C"]}),
1423+
([["a", 1], ["a", 1], ["b", 2], ["b", 3]], {0: ["a", "b"], 1: [1, [2, 3]]}),
1424+
pytest.param(
1425+
[["a", 1], ["a", 2], ["b", 3], ["b", 3]],
1426+
{0: ["a", "b"], 1: [[1, 2], 3]},
1427+
marks=pytest.mark.xfail,
1428+
),
1429+
],
1430+
)
1431+
def test_agg_of_mode_list(test, constant):
1432+
# GH#25581
1433+
df1 = DataFrame(test)
1434+
result = df1.groupby(0).agg(Series.mode)
1435+
# Mode usually only returns 1 value, but can return a list in the case of a tie.
1436+
1437+
expected = DataFrame(constant)
1438+
expected = expected.set_index(0)
1439+
1440+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)