Skip to content

Commit

Permalink
Preserve name for PeriodIndex field accessors
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisvandenbossche committed Mar 22, 2017
1 parent cdf6cae commit 96ed069
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions pandas/tests/indexes/period/test_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion pandas/tseries/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 96ed069

Please sign in to comment.