Skip to content

Add test for #32108 (error with groupby on series with period index) #33105

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

Merged
merged 12 commits into from
Jun 24, 2020
12 changes: 12 additions & 0 deletions pandas/tests/groupby/test_grouping.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,18 @@ def test_grouper_index_types(self):
df.index = list(reversed(df.index.tolist()))
df.groupby(list("abcde")).apply(lambda x: x)

def test_grouper_period_index(self):
# GH 32108
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this to pandas/tests/groupby/test_timegrouper.py

periods = 2
index = pd.period_range(start="2018-01", periods=periods, freq="M")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pass name=

period_serie = pd.Series(range(periods), index=index)
period_serie.index.name = "Month"
result = period_serie.groupby(period_serie.index.month).sum()

expected = pd.Series(range(0, periods), index=range(1, periods + 1))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can construct the Index(...., name=...)

expected.index.name = period_serie.index.name
tm.assert_series_equal(result, expected)

def test_grouper_multilevel_freq(self):

# GH 7885
Expand Down