Skip to content

TST: adding new test for groupby cumsum with named aggregate #50033

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

24 changes: 24 additions & 0 deletions pandas/tests/extension/base/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,30 @@ def test_groupby_agg_extension(self, data_for_grouping):
result = df.groupby("A").first()
self.assert_frame_equal(result, expected)

def test_groupby_agg_extension_timedelta_cumsum_with_named_aggregation(self):
# GH#41720
expected = pd.DataFrame(
{
"td": {
0: pd.Timedelta("0 days 01:00:00"),
1: pd.Timedelta("0 days 01:15:00"),
2: pd.Timedelta("0 days 01:15:00"),
}
}
)
df = pd.DataFrame(
{
"td": pd.Series(
["0 days 01:00:00", "0 days 00:15:00", "0 days 01:15:00"],
dtype="timedelta64[ns]",
),
"grps": ["a", "a", "b"],
}
)
gb = df.groupby("grps")
result = gb.agg(td=("td", "cumsum"))
self.assert_frame_equal(result, expected)

def test_groupby_extension_no_sort(self, data_for_grouping):
df = pd.DataFrame({"A": [1, 1, 2, 2, 3, 3, 1, 4], "B": data_for_grouping})
result = df.groupby("B", sort=False).A.mean()
Expand Down