Skip to content

Commit 5f8ba79

Browse files
committed
DOC: whatsnew v0.21.0 entry (in API changes section)
1 parent a16366a commit 5f8ba79

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

doc/source/whatsnew.rst

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ What's New
1818

1919
These are new features and improvements of note in each release.
2020

21+
.. include:: whatsnew/v0.21.0.txt
22+
2123
.. include:: whatsnew/v0.20.0.txt
2224

2325
.. include:: whatsnew/v0.19.2.txt

doc/source/whatsnew/v0.21.0.txt

+78
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,84 @@ Other Enhancements
3434
Backwards incompatible API changes
3535
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3636

37+
.. _whatsnew_0210.api_breaking.period_index_resampling:
38+
39+
``PeriodIndex`` resampling
40+
^^^^^^^^^^^^^^^^^^^^^^^^^^
41+
42+
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`).
43+
44+
Previous Behavior:
45+
46+
.. code-block:: ipython
47+
48+
In [1]: pi = pd.period_range('2017-01', periods=12, freq='M')
49+
50+
In [2]: s = pd.Series(np.arange(12), index=pi)
51+
52+
In [3]: resampled = s.resample('2Q').mean()
53+
54+
In [4]: resampled
55+
Out[4]:
56+
2017-03-31 1.0
57+
2017-09-30 5.5
58+
2018-03-31 10.0
59+
Freq: 2Q-DEC, dtype: float64
60+
61+
In [5]: resampled.index
62+
Out[5]: DatetimeIndex(['2017-03-31', '2017-09-30', '2018-03-31'], dtype='datetime64[ns]', freq='2Q-DEC')
63+
64+
New Behavior:
65+
66+
.. ipython:: python
67+
68+
pi = pd.period_range('2017-01', periods=12, freq='M')
69+
70+
s = pd.Series(np.arange(12), index=pi)
71+
72+
resampled = s.resample('2Q').mean()
73+
74+
resampled
75+
76+
resampled.index
77+
78+
79+
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.
80+
81+
Previous Behavior:
82+
83+
.. code-block:: ipython
84+
85+
In [1]: pi = pd.PeriodIndex(start='2000-01-01', freq='D', periods=10)
86+
87+
In [2]: s = pd.Series(np.arange(10), index=pi)
88+
89+
In [3]: s.resample('H').ohlc()
90+
Out[3]:
91+
2000-01-01 00:00 0.0
92+
...
93+
2000-01-10 23:00 NaN
94+
Freq: H, Length: 240, dtype: float64
95+
96+
In [4]: s.resample('M').ohlc()
97+
Out[4]:
98+
open high low close
99+
2000-01 0 9 0 9
100+
101+
New Behavior:
102+
103+
.. ipython:: python
104+
105+
pi = pd.PeriodIndex(start='2000-01-01', freq='D', periods=10)
106+
107+
s = pd.Series(np.arange(10), index=pi)
108+
109+
s.resample('H').ohlc()
110+
111+
s.resample('M').ohlc()
112+
113+
114+
As a minor enhancement, resampling a ``PeriodIndex`` can now handle ``NaT`` values (:issue:`13224`)
37115

38116

39117
.. _whatsnew_0210.api:

0 commit comments

Comments
 (0)