Skip to content

Commit 4ab9288

Browse files
authored
[MRG] TST: Added test for groupby apply datetimeindex fix (#36671)
* TST: Added test for groupby apply datetimeindex fix * TST: Moved test to similar tests
1 parent 40daf00 commit 4ab9288

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

pandas/tests/groupby/test_apply.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,23 @@ def test_apply_aggregating_timedelta_and_datetime():
681681
tm.assert_frame_equal(result, expected)
682682

683683

684+
def test_apply_groupby_datetimeindex():
685+
# GH 26182
686+
# groupby apply failed on dataframe with DatetimeIndex
687+
688+
data = [["A", 10], ["B", 20], ["B", 30], ["C", 40], ["C", 50]]
689+
df = pd.DataFrame(
690+
data, columns=["Name", "Value"], index=pd.date_range("2020-09-01", "2020-09-05")
691+
)
692+
693+
result = df.groupby("Name").sum()
694+
695+
expected = pd.DataFrame({"Name": ["A", "B", "C"], "Value": [10, 50, 90]})
696+
expected.set_index("Name", inplace=True)
697+
698+
tm.assert_frame_equal(result, expected)
699+
700+
684701
def test_time_field_bug():
685702
# Test a fix for the following error related to GH issue 11324 When
686703
# non-key fields in a group-by dataframe contained time-based fields

0 commit comments

Comments
 (0)