Skip to content

Commit 96ed069

Browse files
Preserve name for PeriodIndex field accessors
1 parent cdf6cae commit 96ed069

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
@@ -658,11 +658,11 @@ def test_negative_ordinals(self):
658658

659659
def test_pindex_fieldaccessor_nat(self):
660660
idx = PeriodIndex(['2011-01', '2011-02', 'NaT',
661-
'2012-03', '2012-04'], freq='D')
661+
'2012-03', '2012-04'], freq='D', name='name')
662662

663-
exp = Index([2011, 2011, -1, 2012, 2012], dtype=np.int64)
663+
exp = Index([2011, 2011, -1, 2012, 2012], dtype=np.int64, name='name')
664664
self.assert_index_equal(idx.year, exp)
665-
exp = Index([1, 2, -1, 3, 4], dtype=np.int64)
665+
exp = Index([1, 2, -1, 3, 4], dtype=np.int64, name='name')
666666
self.assert_index_equal(idx.month, exp)
667667

668668
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)