Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API: return Index instead of array from DatetimeIndex field accessors (GH15022) #15589

Prev Previous commit
doc fixes
jorisvandenbossche committed Mar 22, 2017
commit ffacd384b04edf5280da74d3bdce2f624a48c24d
8 changes: 5 additions & 3 deletions doc/source/whatsnew/v0.20.0.txt
Original file line number Diff line number Diff line change
@@ -472,14 +472,16 @@ New Behavior:
s.map(lambda x: x.hour)


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a ref here

.. _whatsnew_0200.api_breaking.index_dt_field:

Accessing datetime fields of Index now return Index
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The several datetime-related attributes (see :ref:`here <timeseries.components>`
for an overview) of DatetimeIndex, PeriodIndex and TimedeltaIndex previously
for an overview) of ``DatetimeIndex``, ``PeriodIndex`` and ``TimedeltaIndex`` previously
returned numpy arrays, now they will return a new Index object (:issue:`15022`).
Only in case of a boolean field, still a boolean array is returned to support
boolean indexing.
Only in the case of a boolean field, a the return value is still a boolean array
instead of an Index (to support boolean indexing).

Previous behaviour:

2 changes: 1 addition & 1 deletion pandas/tests/indexes/datetimes/test_misc.py
Original file line number Diff line number Diff line change
@@ -260,7 +260,7 @@ def test_datetimeindex_accessors(self):

# non boolean accessors -> return Index
for accessor in ['year', 'month', 'day', 'hour', 'minute',
'second', 'microsecond', 'nanosecond',
'second', 'microsecond', 'nanosecond',
'dayofweek', 'dayofyear', 'weekofyear',
'quarter', 'weekday_name']:
res = getattr(dti, accessor)