@@ -66,6 +66,36 @@ Current Behavior:
66
66
67
67
result
68
68
69
+
70
+ .. _whatsnew_0240.enhancements.interval:
71
+
72
+ Storing Interval Data in Series and DataFrame
73
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
74
+
75
+ Interval data may now be stored in a ``Series`` or ``DataFrame``, in addition to an
76
+ :class:`IntervalIndex` like previously (:issue:`19453`).
77
+
78
+ .. ipython:: python
79
+
80
+ ser = pd.Series(pd.interval_range(0, 5))
81
+ ser
82
+ ser.dtype
83
+
84
+ Previously, these would be cast to a NumPy array of ``Interval`` objects. In general,
85
+ this should result in better performance when storing an array of intervals in
86
+ a :class:`Series`.
87
+
88
+ Note that the ``.values`` of a ``Series`` containing intervals is no longer a NumPy
89
+ array, but rather an ``ExtensionArray``:
90
+
91
+ .. ipython:: python
92
+
93
+ ser.values
94
+
95
+ This is the same behavior as ``Series.values`` for categorical data. See
96
+ :ref:`whatsnew_0240.api_breaking.interval_values` for more.
97
+
98
+
69
99
.. _whatsnew_0240.enhancements.other:
70
100
71
101
Other Enhancements
@@ -91,6 +121,45 @@ Other Enhancements
91
121
Backwards incompatible API changes
92
122
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
93
123
124
+
125
+ .. _whatsnew_0240.api_breaking.interval_values:
126
+
127
+ ``IntervalIndex.values`` is now an ``IntervalArray``
128
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
129
+
130
+ The :attr:`~Interval.values` attribute of an :class:`IntervalIndex` now returns an
131
+ ``IntervalArray``, rather than a NumPy array of :class:`Interval` objects (:issue:`19453`).
132
+
133
+ Previous Behavior:
134
+
135
+ .. code-block:: ipython
136
+
137
+ In [1]: idx = pd.interval_range(0, 4)
138
+
139
+ In [2]: idx.values
140
+ Out[2]:
141
+ array([Interval(0, 1, closed='right'), Interval(1, 2, closed='right'),
142
+ Interval(2, 3, closed='right'), Interval(3, 4, closed='right')],
143
+ dtype=object)
144
+
145
+ New Behavior:
146
+
147
+ .. ipython:: python
148
+
149
+ idx = pd.interval_range(0, 4)
150
+ idx.values
151
+
152
+ This mirrors ``CateogricalIndex.values``, which returns a ``Categorical``.
153
+
154
+ For situations where you need an ``ndarray`` of ``Interval`` objects, use
155
+ :meth:`numpy.asarray` or ``idx.astype(object)``.
156
+
157
+ .. ipython:: python
158
+
159
+ np.asarray(idx)
160
+ idx.values.astype(object)
161
+
162
+
94
163
.. _whatsnew_0240.api.datetimelike.normalize:
95
164
96
165
Tick DateOffset Normalize Restrictions
@@ -350,6 +419,7 @@ Interval
350
419
^^^^^^^^
351
420
352
421
- Bug in the :class:`IntervalIndex` constructor where the ``closed`` parameter did not always override the inferred ``closed`` (:issue:`19370`)
422
+ - Bug in the ``IntervalIndex`` repr where a trailing comma was missing after the list of intervals (:issue:`20611`)
353
423
-
354
424
-
355
425
0 commit comments