Skip to content

Commit 063b4af

Browse files
winklerandjreback
authored andcommitted
DOC: whatsnew v0.21.0 entry (in API changes section)
1 parent f1f6f02 commit 063b4af

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

doc/source/whatsnew/v0.21.0.txt

+78
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,84 @@ Other Enhancements
170170
Backwards incompatible API changes
171171
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
172172

173+
.. _whatsnew_0210.api_breaking.period_index_resampling:
174+
175+
``PeriodIndex`` resampling
176+
^^^^^^^^^^^^^^^^^^^^^^^^^^
177+
178+
In previous versions of pandas, resampling a ``Series``/``DataFrame`` indexed by a ``PeriodIndex`` returned a ``DatetimeIndex`` in some cases (:issue:`12884`). Resampling to a multiplied frequency now returns a ``PeriodIndex`` (:issue:`15944`).
179+
180+
Previous Behavior:
181+
182+
.. code-block:: ipython
183+
184+
In [1]: pi = pd.period_range('2017-01', periods=12, freq='M')
185+
186+
In [2]: s = pd.Series(np.arange(12), index=pi)
187+
188+
In [3]: resampled = s.resample('2Q').mean()
189+
190+
In [4]: resampled
191+
Out[4]:
192+
2017-03-31 1.0
193+
2017-09-30 5.5
194+
2018-03-31 10.0
195+
Freq: 2Q-DEC, dtype: float64
196+
197+
In [5]: resampled.index
198+
Out[5]: DatetimeIndex(['2017-03-31', '2017-09-30', '2018-03-31'], dtype='datetime64[ns]', freq='2Q-DEC')
199+
200+
New Behavior:
201+
202+
.. ipython:: python
203+
204+
pi = pd.period_range('2017-01', periods=12, freq='M')
205+
206+
s = pd.Series(np.arange(12), index=pi)
207+
208+
resampled = s.resample('2Q').mean()
209+
210+
resampled
211+
212+
resampled.index
213+
214+
215+
Upsampling and calling ``.ohlc()`` previously returned a ``Series``, basically identical to calling ``.asfreq()``. OHLC upsampling now returns a DataFrame with columns ``open``, ``high``, ``low`` and ``close`` (:issue:`13083`). This is consistent with downsampling and ``DatetimeIndex`` behavior.
216+
217+
Previous Behavior:
218+
219+
.. code-block:: ipython
220+
221+
In [1]: pi = pd.PeriodIndex(start='2000-01-01', freq='D', periods=10)
222+
223+
In [2]: s = pd.Series(np.arange(10), index=pi)
224+
225+
In [3]: s.resample('H').ohlc()
226+
Out[3]:
227+
2000-01-01 00:00 0.0
228+
...
229+
2000-01-10 23:00 NaN
230+
Freq: H, Length: 240, dtype: float64
231+
232+
In [4]: s.resample('M').ohlc()
233+
Out[4]:
234+
open high low close
235+
2000-01 0 9 0 9
236+
237+
New Behavior:
238+
239+
.. ipython:: python
240+
241+
pi = pd.PeriodIndex(start='2000-01-01', freq='D', periods=10)
242+
243+
s = pd.Series(np.arange(10), index=pi)
244+
245+
s.resample('H').ohlc()
246+
247+
s.resample('M').ohlc()
248+
249+
250+
As a minor enhancement, resampling a ``PeriodIndex`` can now handle ``NaT`` values (:issue:`13224`)
173251

174252
.. _whatsnew_0210.api_breaking.deps:
175253

0 commit comments

Comments
 (0)