Skip to content

Commit 398a684

Browse files
winklerandjreback
authored andcommitted
DOC: whatsnew v0.21.0 entry (in API changes section)
1 parent 41401d4 commit 398a684

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

doc/source/whatsnew/v0.21.0.txt

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,84 @@ Other Enhancements
171171
Backwards incompatible API changes
172172
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
173173

174+
.. _whatsnew_0210.api_breaking.period_index_resampling:
175+
176+
``PeriodIndex`` resampling
177+
^^^^^^^^^^^^^^^^^^^^^^^^^^
178+
179+
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`).
180+
181+
Previous Behavior:
182+
183+
.. code-block:: ipython
184+
185+
In [1]: pi = pd.period_range('2017-01', periods=12, freq='M')
186+
187+
In [2]: s = pd.Series(np.arange(12), index=pi)
188+
189+
In [3]: resampled = s.resample('2Q').mean()
190+
191+
In [4]: resampled
192+
Out[4]:
193+
2017-03-31 1.0
194+
2017-09-30 5.5
195+
2018-03-31 10.0
196+
Freq: 2Q-DEC, dtype: float64
197+
198+
In [5]: resampled.index
199+
Out[5]: DatetimeIndex(['2017-03-31', '2017-09-30', '2018-03-31'], dtype='datetime64[ns]', freq='2Q-DEC')
200+
201+
New Behavior:
202+
203+
.. ipython:: python
204+
205+
pi = pd.period_range('2017-01', periods=12, freq='M')
206+
207+
s = pd.Series(np.arange(12), index=pi)
208+
209+
resampled = s.resample('2Q').mean()
210+
211+
resampled
212+
213+
resampled.index
214+
215+
216+
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.
217+
218+
Previous Behavior:
219+
220+
.. code-block:: ipython
221+
222+
In [1]: pi = pd.PeriodIndex(start='2000-01-01', freq='D', periods=10)
223+
224+
In [2]: s = pd.Series(np.arange(10), index=pi)
225+
226+
In [3]: s.resample('H').ohlc()
227+
Out[3]:
228+
2000-01-01 00:00 0.0
229+
...
230+
2000-01-10 23:00 NaN
231+
Freq: H, Length: 240, dtype: float64
232+
233+
In [4]: s.resample('M').ohlc()
234+
Out[4]:
235+
open high low close
236+
2000-01 0 9 0 9
237+
238+
New Behavior:
239+
240+
.. ipython:: python
241+
242+
pi = pd.PeriodIndex(start='2000-01-01', freq='D', periods=10)
243+
244+
s = pd.Series(np.arange(10), index=pi)
245+
246+
s.resample('H').ohlc()
247+
248+
s.resample('M').ohlc()
249+
250+
251+
As a minor enhancement, resampling a ``PeriodIndex`` can now handle ``NaT`` values (:issue:`13224`)
174252

175253
.. _whatsnew_0210.api_breaking.deps:
176254

0 commit comments

Comments
 (0)