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=

periodSerie = pd.Series(range(periods), index=index)
Copy link
Member

@MarcoGorelli MarcoGorelli Apr 4, 2020

Choose a reason for hiding this comment

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

naming this periodSerie doesn't conform to PEP8 - sorry for not bringing this up sooner, I thought flake8 would've caught it. seems there's an open issue to add extra plugins though (#20588)

Function and Variable Names
Function names should be lowercase, with words separated by underscores as necessary to improve readability.

Variable names follow the same convention as function names.

mixedCase is allowed only in contexts where that's already the prevailing style (e.g. threading.py), to retain backwards compatibility.

https://www.python.org/dev/peps/pep-0008/

Choose a reason for hiding this comment

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

Done, I hope it's all good now :)

periodSerie.index.name = "Month"
result = periodSerie.groupby(periodSerie.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 = periodSerie.index.name
tm.assert_series_equal(result, expected)

def test_grouper_multilevel_freq(self):

# GH 7885
Expand Down