From 20a203da253e572cd8f7ec52e14aa38689335d6d Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Tue, 7 Mar 2017 15:26:40 +0100 Subject: [PATCH] Preserve name for PeriodIndex field accessors --- pandas/tests/indexes/period/test_period.py | 6 +++--- pandas/tseries/period.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/tests/indexes/period/test_period.py b/pandas/tests/indexes/period/test_period.py index 16b8ce65698025..3deeefbc843eea 100644 --- a/pandas/tests/indexes/period/test_period.py +++ b/pandas/tests/indexes/period/test_period.py @@ -651,11 +651,11 @@ def test_negative_ordinals(self): def test_pindex_fieldaccessor_nat(self): idx = PeriodIndex(['2011-01', '2011-02', 'NaT', - '2012-03', '2012-04'], freq='D') + '2012-03', '2012-04'], freq='D', name='name') - exp = Index([2011, 2011, -1, 2012, 2012], dtype=np.int64) + exp = Index([2011, 2011, -1, 2012, 2012], dtype=np.int64, name='name') self.assert_index_equal(idx.year, exp) - exp = Index([1, 2, -1, 3, 4], dtype=np.int64) + exp = Index([1, 2, -1, 3, 4], dtype=np.int64, name='name') self.assert_index_equal(idx.month, exp) def test_pindex_qaccess(self): diff --git a/pandas/tseries/period.py b/pandas/tseries/period.py index 56f88b7ed800c0..7c225209730e24 100644 --- a/pandas/tseries/period.py +++ b/pandas/tseries/period.py @@ -53,7 +53,7 @@ def _field_accessor(name, alias, docstring=None): def f(self): base, mult = _gfc(self.freq) result = get_period_field_arr(alias, self._values, base) - return Index(result) + return Index(result, name=self.name) f.__name__ = name f.__doc__ = docstring return property(f)