Skip to content

Commit

Permalink
TST: Add test case for groupby where by column contains values with s…
Browse files Browse the repository at this point in the history
…ame starting value (#46721)

GH29635

Co-authored-by: Mateusz <mateusz.cytrynski@gmail.com>
  • Loading branch information
FactorizeD and Mateusz authored Apr 9, 2022
1 parent b3b5e2a commit 8172879
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions pandas/tests/groupby/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 8172879

Please sign in to comment.