diff --git a/doc/source/whatsnew/v1.1.0.rst b/doc/source/whatsnew/v1.1.0.rst index 20415bba99476..b92a3929ace41 100644 --- a/doc/source/whatsnew/v1.1.0.rst +++ b/doc/source/whatsnew/v1.1.0.rst @@ -452,6 +452,7 @@ Other - Fixed bug in :func:`pandas.testing.assert_series_equal` where dtypes were checked for ``Interval`` and ``ExtensionArray`` operands when ``check_dtype`` was ``False`` (:issue:`32747`) - Bug in :meth:`Series.map` not raising on invalid ``na_action`` (:issue:`32815`) - Bug in :meth:`DataFrame.__dir__` caused a segfault when using unicode surrogates in a column name (:issue:`25509`) +- Added test for named period index, doing group by on index.(:issue:`32108`) .. --------------------------------------------------------------------------- diff --git a/pandas/tests/groupby/test_groupby.py b/pandas/tests/groupby/test_groupby.py index b8d8f56512a69..688092f85d4fc 100644 --- a/pandas/tests/groupby/test_groupby.py +++ b/pandas/tests/groupby/test_groupby.py @@ -8,7 +8,16 @@ 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 @@ -2057,3 +2066,15 @@ def test_groups_repr_truncates(max_seq_items, expected): result = df.groupby(np.array(df.a)).groups.__repr__() assert result == expected + + +def test_groupby_period_index(): + periods = 2 + index = period_range(start="2018-01", periods=periods, freq="M") + period_series = Series(range(periods), index=index) + period_series.index.name = "Month" + result = period_series.groupby(period_series.index.month).sum() + + expected = pd.Series(range(0, periods), index=range(1, periods + 1)) + expected.index.name = period_series.index.name + tm.assert_series_equal(result, expected)