Skip to content

Commit 6317b6b

Browse files
Add whatsnew
1 parent 96ed069 commit 6317b6b

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
@@ -471,6 +471,36 @@ New Behavior:
471471

472472
s.map(lambda x: x.hour)
473473

474+
475+
Accessing datetime fields of Index now return Index
476+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
477+
478+
The several datetime-related attributes (see :ref:`here <timeseries.components>`
479+
for an overview) of DatetimeIndex, PeriodIndex and TimedeltaIndex previously
480+
returned numpy arrays, now they will return a new Index object (:issue:`15022`).
481+
482+
Previous behaviour:
483+
484+
.. code-block:: ipython
485+
486+
In [1]: idx = pd.date_range("2015-01-01", periods=5, freq='10H')
487+
488+
In [2]: idx.hour
489+
Out[2]: array([ 0, 10, 20, 6, 16], dtype=int32)
490+
491+
New Behavior:
492+
493+
.. ipython:: python
494+
495+
idx = pd.date_range("2015-01-01", periods=5, freq='10H')
496+
idx.hour
497+
498+
This has the advantage that specific Index methods are still available on the
499+
result. On the other hand, this might have backward incompatibilities: e.g.
500+
compared to numpy arrays, Index objects are not mutable (values cannot be set
501+
by indexing). To get the original result, you can convert to a nunpy array
502+
explicitly using ``np.asarray(idx.hour)``.
503+
474504
.. _whatsnew_0200.api_breaking.s3:
475505

476506
S3 File Handling

0 commit comments

Comments
 (0)