Skip to content

Commit

Permalink
Preserve name for DatetimeIndex field accessors
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisvandenbossche committed Mar 22, 2017
1 parent f2831e2 commit cdf6cae
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions pandas/tests/indexes/datetimes/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ def test_normalize(self):
class TestDatetime64(tm.TestCase):

def test_datetimeindex_accessors(self):
<<<<<<< f2831e2a2074e27e5cd3cfc0728d989742ee4680
dti_naive = DatetimeIndex(freq='D', start=datetime(1998, 1, 1),
periods=365)
# GH 13303
Expand Down Expand Up @@ -255,6 +256,19 @@ def test_datetimeindex_accessors(self):
self.assertEqual(len(dti.is_year_end), 365)
self.assertEqual(len(dti.weekday_name), 365)

dti.name = 'name'

for accessor in ['year', 'month', 'day', 'hour', 'minute', 'second',
'microsecond', 'nanosecond', 'dayofweek', 'dayofyear',
'weekofyear', 'quarter',
'is_month_start', 'is_month_end',
'is_quarter_start', 'is_quarter_end',
'is_year_start', 'is_year_end', 'weekday_name']:
res = getattr(dti, accessor)
self.assertEqual(len(res), 365)
self.assertIsInstance(res, Index)
self.assertEqual(res.name, 'name')

dti = DatetimeIndex(freq='BQ-FEB', start=datetime(1998, 1, 1),
periods=4)

Expand Down
2 changes: 1 addition & 1 deletion pandas/tseries/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def f(self):
result = libts.get_date_field(values, field)
result = self._maybe_mask_results(result, convert='float64')

return Index(result)
return Index(result, name=self.name)

f.__name__ = name
f.__doc__ = docstring
Expand Down

0 comments on commit cdf6cae

Please sign in to comment.