Skip to content

Commit 20a203d

Browse files
Preserve name for PeriodIndex field accessors
1 parent 45b838a commit 20a203d

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

pandas/tests/indexes/period/test_period.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -651,11 +651,11 @@ def test_negative_ordinals(self):
651651

652652
def test_pindex_fieldaccessor_nat(self):
653653
idx = PeriodIndex(['2011-01', '2011-02', 'NaT',
654-
'2012-03', '2012-04'], freq='D')
654+
'2012-03', '2012-04'], freq='D', name='name')
655655

656-
exp = Index([2011, 2011, -1, 2012, 2012], dtype=np.int64)
656+
exp = Index([2011, 2011, -1, 2012, 2012], dtype=np.int64, name='name')
657657
self.assert_index_equal(idx.year, exp)
658-
exp = Index([1, 2, -1, 3, 4], dtype=np.int64)
658+
exp = Index([1, 2, -1, 3, 4], dtype=np.int64, name='name')
659659
self.assert_index_equal(idx.month, exp)
660660

661661
def test_pindex_qaccess(self):

pandas/tseries/period.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def _field_accessor(name, alias, docstring=None):
5353
def f(self):
5454
base, mult = _gfc(self.freq)
5555
result = get_period_field_arr(alias, self._values, base)
56-
return Index(result)
56+
return Index(result, name=self.name)
5757
f.__name__ = name
5858
f.__doc__ = docstring
5959
return property(f)

0 commit comments

Comments
 (0)