Skip to content

Commit cdf6cae

Browse files
Preserve name for DatetimeIndex field accessors
1 parent f2831e2 commit cdf6cae

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

pandas/tests/indexes/datetimes/test_misc.py

+14
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ def test_normalize(self):
172172
class TestDatetime64(tm.TestCase):
173173

174174
def test_datetimeindex_accessors(self):
175+
<<<<<<< f2831e2a2074e27e5cd3cfc0728d989742ee4680
175176
dti_naive = DatetimeIndex(freq='D', start=datetime(1998, 1, 1),
176177
periods=365)
177178
# GH 13303
@@ -255,6 +256,19 @@ def test_datetimeindex_accessors(self):
255256
self.assertEqual(len(dti.is_year_end), 365)
256257
self.assertEqual(len(dti.weekday_name), 365)
257258

259+
dti.name = 'name'
260+
261+
for accessor in ['year', 'month', 'day', 'hour', 'minute', 'second',
262+
'microsecond', 'nanosecond', 'dayofweek', 'dayofyear',
263+
'weekofyear', 'quarter',
264+
'is_month_start', 'is_month_end',
265+
'is_quarter_start', 'is_quarter_end',
266+
'is_year_start', 'is_year_end', 'weekday_name']:
267+
res = getattr(dti, accessor)
268+
self.assertEqual(len(res), 365)
269+
self.assertIsInstance(res, Index)
270+
self.assertEqual(res.name, 'name')
271+
258272
dti = DatetimeIndex(freq='BQ-FEB', start=datetime(1998, 1, 1),
259273
periods=4)
260274

pandas/tseries/index.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def f(self):
8585
result = libts.get_date_field(values, field)
8686
result = self._maybe_mask_results(result, convert='float64')
8787

88-
return Index(result)
88+
return Index(result, name=self.name)
8989

9090
f.__name__ = name
9191
f.__doc__ = docstring

0 commit comments

Comments
 (0)