@@ -138,32 +138,40 @@ Current Behavior:
138
138
139
139
.. _whatsnew_0240.enhancements.interval:
140
140
141
- Storing Interval Data in Series and DataFrame
142
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
141
+ Storing Interval and Period Data in Series and DataFrame
142
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
143
143
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 `).
146
146
147
147
.. ipython:: python
148
148
149
149
ser = pd.Series(pd.interval_range(0, 5))
150
150
ser
151
151
ser.dtype
152
152
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
156
160
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
158
166
array, but rather an ``ExtensionArray``:
159
167
160
168
.. ipython:: python
161
169
162
170
ser.values
171
+ pser.values
163
172
164
173
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.
167
175
168
176
.. _whatsnew_0240.enhancements.other:
169
177
@@ -231,13 +239,51 @@ New Behavior:
231
239
This mirrors ``CategoricalIndex.values``, which returns a ``Categorical``.
232
240
233
241
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)``.
235
243
236
244
.. ipython:: python
237
245
238
246
np.asarray(idx)
239
247
idx.values.astype(object)
240
248
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
+
241
287
.. _whatsnew_0240.api.timezone_offset_parsing:
242
288
243
289
Parsing Datetime Strings with Timezone Offsets
0 commit comments