Skip to content

Commit 012be1c

Browse files
committed
docs
1 parent 2c0311c commit 012be1c

File tree

1 file changed

+57
-11
lines changed

1 file changed

+57
-11
lines changed

doc/source/whatsnew/v0.24.0.txt

+57-11
Original file line numberDiff line numberDiff line change
@@ -138,32 +138,40 @@ Current Behavior:
138138

139139
.. _whatsnew_0240.enhancements.interval:
140140

141-
Storing Interval Data in Series and DataFrame
142-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
141+
Storing Interval and Period Data in Series and DataFrame
142+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
143143

144-
Interval data may now be stored in a ``Series`` or ``DataFrame``, in addition to an
145-
:class:`IntervalIndex` like previously (:issue:`19453`).
144+
Interval and Period data may now be stored in a ``Series`` or ``DataFrame``, in addition to an
145+
:class:`IntervalIndex` and :class:`PeriodIndex` like previously (:issue:`19453`, :issue:`22862`).
146146

147147
.. ipython:: python
148148

149149
ser = pd.Series(pd.interval_range(0, 5))
150150
ser
151151
ser.dtype
152152

153-
Previously, these would be cast to a NumPy array of ``Interval`` objects. In general,
154-
this should result in better performance when storing an array of intervals in
155-
a :class:`Series`.
153+
And for periods:
154+
155+
.. ipython:: python
156+
157+
pser = pd.Series(pd.date_range("2000", freq="D", periods=5))
158+
pser
159+
pser.dtype
156160

157-
Note that the ``.values`` of a ``Series`` containing intervals is no longer a NumPy
161+
Previously, these would be cast to a NumPy array with object dtype. In general,
162+
this should result in better performance when storing an array of intervals or periods
163+
in a :class:`Series`.
164+
165+
Note that the ``.values`` of a ``Series`` containing one of these types is no longer a NumPy
158166
array, but rather an ``ExtensionArray``:
159167

160168
.. ipython:: python
161169

162170
ser.values
171+
pser.values
163172

164173
This is the same behavior as ``Series.values`` for categorical data. See
165-
:ref:`whatsnew_0240.api_breaking.interval_values` for more.
166-
174+
:ref:`whatsnew_0240.api_breaking.interval_values` and :ref:`whatsnew_0240.api_breaking.period_values` for more.
167175

168176
.. _whatsnew_0240.enhancements.other:
169177

@@ -231,13 +239,51 @@ New Behavior:
231239
This mirrors ``CategoricalIndex.values``, which returns a ``Categorical``.
232240

233241
For situations where you need an ``ndarray`` of ``Interval`` objects, use
234-
:meth:`numpy.asarray` or ``idx.astype(object)``.
242+
:meth:`numpy.asarray` or ``idx.values.astype(object)``.
235243

236244
.. ipython:: python
237245

238246
np.asarray(idx)
239247
idx.values.astype(object)
240248

249+
250+
.. _whatsnew_0240.api_breaking.period_values:
251+
252+
``PeriodIndex.values`` is now a ``PeriodArray``
253+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
254+
255+
The ``values`` attribute of a :class:`PeriodIndex` now returns a ``PeriodArray``
256+
rather than a NumPy array of :class:`Period` objects (:issue:`22862`).
257+
258+
Previous Behavior:
259+
260+
.. code-block:: ipython
261+
262+
In [1]: idx = pd.period_range("2000", freq="D", periods=4)
263+
264+
In [2]: idx.values
265+
Out [2]:
266+
array([Period('2000-01-01', 'D'), Period('2000-01-02', 'D'),
267+
Period('2000-01-03', 'D'), Period('2000-01-04', 'D')], dtype=object)
268+
269+
New Behavior:
270+
271+
.. ipython:: python
272+
273+
idx = pd.period_range("2000", freq="D", periods=4)
274+
idx.values
275+
276+
This mirrors ``CategoricalIndex.values``, which returns a ``Categorical``.
277+
278+
For situations where you need an ``ndarray`` of ``Period`` objects, use
279+
:meth:`numpy.asarray` or ``idx.values.astype(object)``.
280+
281+
.. ipython:: python
282+
283+
np.asarray(idx)
284+
idx.values.astype(object)
285+
286+
241287
.. _whatsnew_0240.api.timezone_offset_parsing:
242288

243289
Parsing Datetime Strings with Timezone Offsets

0 commit comments

Comments
 (0)