diff --git a/pandas/tests/indexes/period/test_period.py b/pandas/tests/indexes/period/test_period.py index f1051eb828b4e..6a6c0ab49b15d 100644 --- a/pandas/tests/indexes/period/test_period.py +++ b/pandas/tests/indexes/period/test_period.py @@ -658,11 +658,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 8dd48aff29c28..c279d5a9342e8 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)