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
14 changes: 13 additions & 1 deletion pandas/tests/groupby/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pandas.errors import PerformanceWarning

import pandas as pd
from pandas import DataFrame, Index, MultiIndex, Series, Timestamp, date_range, read_csv
from pandas import DataFrame, Index, MultiIndex, Series, Timestamp, date_range, period_range, read_csv
import pandas._testing as tm
from pandas.core.base import SpecificationError
import pandas.core.common as com
Expand Down Expand Up @@ -2057,3 +2057,15 @@ def test_groups_repr_truncates(max_seq_items, expected):

result = df.groupby(np.array(df.a)).groups.__repr__()
assert result == expected


Copy link
Contributor

Choose a reason for hiding this comment

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

can you move this under test_grouper_index_types (same file). ping on green.

Choose a reason for hiding this comment

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

The function test_grouper_index_types is in the file pandas/tests/groupby/test_grouping.py our test is in pandas/tests/groupby/test_groupby.py, do you want us to move our test to test_grouping.py ?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes pls move this

Choose a reason for hiding this comment

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

done

def test_groupby_period_index():
Copy link
Member

Choose a reason for hiding this comment

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

Add the issue number here:

def test_groupby_period_index():
    # GH 32108

periods = 2
index = period_range(start='2018-01', periods=periods, freq='M')
Copy link
Member

Choose a reason for hiding this comment

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

Looks like you haven't run black, and perhaps not flake8 either. See code standards

periodSerie = Series(range(periods), index=index)
periodSerie.index.name = 'Month'
result = periodSerie.groupby(periodSerie.index.month).sum()

expected = pd.Series(range(0, periods), index=range(1, periods + 1))
expected.index.name = periodSerie.index.name
tm.assert_series_equal(result, expected)