Skip to content

Commit 4200e1f

Browse files
author
Mateusz
committed
TST: Add test case for groupby where by column contains values with same starting value
GH29635
1 parent b3b5e2a commit 4200e1f

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

pandas/tests/groupby/test_groupby.py

+23
Original file line numberDiff line numberDiff line change
@@ -2658,3 +2658,26 @@ def test_pad_backfill_deprecation():
26582658
s.groupby(level=0).backfill()
26592659
with tm.assert_produces_warning(FutureWarning, match="pad"):
26602660
s.groupby(level=0).pad()
2661+
2662+
2663+
def test_by_column_values_with_same_starting_value():
2664+
# GH29635
2665+
df = DataFrame(
2666+
{
2667+
"Name": ["Thomas", "Thomas", "Thomas John"],
2668+
"Credit": [1200, 1300, 900],
2669+
"Mood": ["sad", "happy", "happy"],
2670+
}
2671+
)
2672+
aggregate_details = {"Mood": Series.mode, "Credit": "sum"}
2673+
2674+
result = df.groupby(["Name"]).agg(aggregate_details)
2675+
expected_result = DataFrame(
2676+
{
2677+
"Mood": [["happy", "sad"], "happy"],
2678+
"Credit": [2500, 900],
2679+
"Name": ["Thomas", "Thomas John"],
2680+
}
2681+
).set_index("Name")
2682+
2683+
tm.assert_frame_equal(result, expected_result)

0 commit comments

Comments
 (0)