From 32b10716af6647a4c8102d833fc3d9293d87c6a2 Mon Sep 17 00:00:00 2001 From: Sumanau Sareen Date: Sat, 28 Mar 2020 20:49:14 +0530 Subject: [PATCH 1/2] Add test for named period index, doing group by index --- pandas/tests/groupby/test_groupby.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/pandas/tests/groupby/test_groupby.py b/pandas/tests/groupby/test_groupby.py index 5662d41e19885..f11e9e2062a7f 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) From 7721aee74657d8e52e7d3b82fd6d6a3d13ca92c8 Mon Sep 17 00:00:00 2001 From: Sumanau Sareen Date: Sat, 28 Mar 2020 20:53:48 +0530 Subject: [PATCH 2/2] Added a whatsnew entry --- doc/source/whatsnew/v1.1.0.rst | 1 + 1 file changed, 1 insertion(+) 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`) .. ---------------------------------------------------------------------------