Skip to content

Commit d097bab

Browse files
committed
DOC/DEPR: pivot_annual
1 parent 506520b commit d097bab

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

doc/source/cookbook.rst

+13
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,19 @@ The :ref:`Pivot <reshaping.pivot>` docs.
679679
'Employed' : lambda x : sum(x),
680680
'Grade' : lambda x : sum(x) / len(x)})
681681
682+
`Plot pandas DataFrame with year over year data
683+
<http://stackoverflow.com/questions/30379789/plot-pandas-data-frame-with-year-over-year-data>`__
684+
685+
To create year and month crosstabulation:
686+
687+
.. ipython:: python
688+
689+
df = pd.DataFrame({'value': np.random.randn(36)},
690+
index=pd.date_range('2011-01-01', freq='M', periods=36))
691+
692+
pd.pivot_table(df, index=df.index.month, columns=df.index.year,
693+
values='value', aggfunc='sum')
694+
682695
Apply
683696
*****
684697

doc/source/whatsnew/v0.19.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ Deprecations
529529
- ``as_recarray`` has been deprecated in ``pd.read_csv()`` and will be removed in a future version (:issue:`13373`)
530530
- top-level ``pd.ordered_merge()`` has been renamed to ``pd.merge_ordered()`` and the original name will be removed in a future version (:issue:`13358`)
531531
- ``Timestamp.offset`` property (and named arg in the constructor), has been deprecated in favor of ``freq`` (:issue:`12160`)
532-
532+
- ``pivot_annual`` is deprecated. Use ``pivot_table`` as alternative, an example is :ref:`here <cookbook.pivot>` (:issue:`736`)
533533

534534
.. _whatsnew_0190.prior_deprecations:
535535

pandas/tseries/tests/test_util.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ def test_daily(self):
2121
rng = date_range('1/1/2000', '12/31/2004', freq='D')
2222
ts = Series(np.random.randn(len(rng)), index=rng)
2323

24-
annual = pivot_annual(ts, 'D')
24+
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
25+
annual = pivot_annual(ts, 'D')
2526

2627
doy = ts.index.dayofyear
2728
doy[(~isleapyear(ts.index.year)) & (doy >= 60)] += 1
@@ -53,7 +54,8 @@ def test_hourly(self):
5354
hoy[~isleapyear(ts_hourly.index.year) & (hoy >= 1416)] += 24
5455
hoy += 1
5556

56-
annual = pivot_annual(ts_hourly)
57+
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
58+
annual = pivot_annual(ts_hourly)
5759

5860
ts_hourly = ts_hourly.astype(float)
5961
for i in [1, 1416, 1417, 1418, 1439, 1440, 1441, 8784]:
@@ -78,7 +80,8 @@ def test_monthly(self):
7880
rng = date_range('1/1/2000', '12/31/2004', freq='M')
7981
ts = Series(np.random.randn(len(rng)), index=rng)
8082

81-
annual = pivot_annual(ts, 'M')
83+
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
84+
annual = pivot_annual(ts, 'M')
8285

8386
month = ts.index.month
8487
for i in range(1, 13):

pandas/tseries/util.py

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import warnings
2+
13
from pandas.compat import lrange
24
import numpy as np
35
from pandas.types.common import _ensure_platform_int
@@ -7,6 +9,8 @@
79

810
def pivot_annual(series, freq=None):
911
"""
12+
Deprecated. Use ``pivot_table`` instead.
13+
1014
Group a series by years, taking leap years into account.
1115
1216
The output has as many rows as distinct years in the original series,
@@ -35,6 +39,10 @@ def pivot_annual(series, freq=None):
3539
-------
3640
annual : DataFrame
3741
"""
42+
43+
msg = "pivot_annual is deprecated. Use pivot_table instead"
44+
warnings.warn(msg, FutureWarning)
45+
3846
index = series.index
3947
year = index.year
4048
years = nanops.unique1d(year)

0 commit comments

Comments
 (0)