Skip to content

Commit 0e208c8

Browse files
TST: Added more test cases pandas-dev#25581
1 parent 1fd0a93 commit 0e208c8

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

pandas/tests/groupby/aggregate/test_aggregate.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -1415,12 +1415,23 @@ def test_multi_axis_1_raises(func):
14151415
gb.agg(func)
14161416

14171417

1418-
def test_agg_of_list():
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+
# This test case still fails
1425+
# ([["a", 1], ["a", 2], ["b", 3], ["b", 3]], {0: ["a", "b"], 1: [[1, 2], 3]})
1426+
],
1427+
)
1428+
def test_agg_of_mode_list(test, constant):
14191429
# GH#25581
1420-
df1 = DataFrame([[20, "A"], [20, "B"], [30, "C"]])
1430+
df1 = DataFrame(test)
14211431
result = df1.groupby(0).agg(Series.mode)
1432+
# Mode usually only returns 1 value, but can return a list in the case of a tie.
14221433

1423-
expected = DataFrame({0: [20, 30], 1: [["A", "B"], "C"]})
1434+
expected = DataFrame(constant)
14241435
expected = expected.set_index(0)
14251436

14261437
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)