Skip to content

TST: Test aggregate with list values #25581 #47559

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions pandas/tests/groupby/aggregate/test_aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -1413,3 +1413,28 @@ def test_multi_axis_1_raises(func):
gb = df.groupby("a", axis=1)
with pytest.raises(NotImplementedError, match="axis other than 0 is not supported"):
gb.agg(func)


@pytest.mark.parametrize(
"test, constant",
[
([[20, "A"], [20, "B"], [10, "C"]], {0: [10, 20], 1: ["C", ["A", "B"]]}),
([[20, "A"], [20, "B"], [30, "C"]], {0: [20, 30], 1: [["A", "B"], "C"]}),
([["a", 1], ["a", 1], ["b", 2], ["b", 3]], {0: ["a", "b"], 1: [1, [2, 3]]}),
pytest.param(
[["a", 1], ["a", 2], ["b", 3], ["b", 3]],
{0: ["a", "b"], 1: [[1, 2], 3]},
marks=pytest.mark.xfail,
),
],
)
def test_agg_of_mode_list(test, constant):
# GH#25581
df1 = DataFrame(test)
result = df1.groupby(0).agg(Series.mode)
# Mode usually only returns 1 value, but can return a list in the case of a tie.

expected = DataFrame(constant)
expected = expected.set_index(0)

tm.assert_frame_equal(result, expected)