Skip to content

Commit 094b6ab

Browse files
Add whatsnew
1 parent 20a203d commit 094b6ab

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

doc/source/whatsnew/v0.20.0.txt

+30
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,36 @@ Map on Index types now return other Index types
392392

393393
s.map(lambda x: x.hour)
394394

395+
396+
Accessing datetime fields of Index now return Index
397+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
398+
399+
The several datetime-related attributes (see :ref:`here <timeseries.components>`
400+
for an overview) of DatetimeIndex, PeriodIndex and TimedeltaIndex previously
401+
returned numpy arrays, now they will return a new Index object (:issue:`15022`).
402+
403+
Previous behaviour:
404+
405+
.. code-block:: ipython
406+
407+
In [1]: idx = pd.date_range("2015-01-01", periods=5, freq='10H')
408+
409+
In [2]: idx.hour
410+
Out[2]: array([ 0, 10, 20, 6, 16], dtype=int32)
411+
412+
New Behavior:
413+
414+
.. ipython:: python
415+
416+
idx = pd.date_range("2015-01-01", periods=5, freq='10H')
417+
idx.hour
418+
419+
This has the advantage that specific Index methods are still available on the
420+
result. On the other hand, this might have backward incompatibilities: e.g.
421+
compared to numpy arrays, Index objects are not mutable (values cannot be set
422+
by indexing). To get the original result, you can convert to a nunpy array
423+
explicitly using ``np.asarray(idx.hour)``.
424+
395425
.. _whatsnew_0200.api_breaking.s3:
396426

397427
S3 File Handling

0 commit comments

Comments
 (0)