From 8172879688f0a21fd89b1b9d77634aac167ff857 Mon Sep 17 00:00:00 2001 From: FactorizeD <26720860+FactorizeD@users.noreply.github.com> Date: Sat, 9 Apr 2022 19:40:00 +0200 Subject: [PATCH] TST: Add test case for groupby where by column contains values with same starting value (#46721) GH29635 Co-authored-by: Mateusz --- pandas/tests/groupby/test_groupby.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/pandas/tests/groupby/test_groupby.py b/pandas/tests/groupby/test_groupby.py index 97e388cd074c3..ed025ada3a36c 100644 --- a/pandas/tests/groupby/test_groupby.py +++ b/pandas/tests/groupby/test_groupby.py @@ -2658,3 +2658,26 @@ def test_pad_backfill_deprecation(): s.groupby(level=0).backfill() with tm.assert_produces_warning(FutureWarning, match="pad"): s.groupby(level=0).pad() + + +def test_by_column_values_with_same_starting_value(): + # GH29635 + df = DataFrame( + { + "Name": ["Thomas", "Thomas", "Thomas John"], + "Credit": [1200, 1300, 900], + "Mood": ["sad", "happy", "happy"], + } + ) + aggregate_details = {"Mood": Series.mode, "Credit": "sum"} + + result = df.groupby(["Name"]).agg(aggregate_details) + expected_result = DataFrame( + { + "Mood": [["happy", "sad"], "happy"], + "Credit": [2500, 900], + "Name": ["Thomas", "Thomas John"], + } + ).set_index("Name") + + tm.assert_frame_equal(result, expected_result)