Skip to content

Commit 1543761

Browse files
topper-123jreback
authored andcommitted
CLN: remove tseries.util.pivot_annual/isleapyear (#18370)
1 parent c4a2cd3 commit 1543761

File tree

3 files changed

+46
-219
lines changed

3 files changed

+46
-219
lines changed

doc/source/whatsnew/v0.22.0.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ Removal of prior version deprecations/changes
7676

7777
- Warnings against the obsolete usage ``Categorical(codes, categories)``, which were emitted for instance when the first two arguments to ``Categorical()`` had different dtypes, and recommended the use of ``Categorical.from_codes``, have now been removed (:issue:`8074`)
7878
- The ``levels`` and ``labels`` attributes of a ``MultiIndex`` can no longer be set directly (:issue:`4039`).
79-
-
79+
- ``pd.tseries.util.pivot_annual`` has been removed (deprecated since v0.19). Use ``pivot_table`` instead (:issue:`18370`)
80+
- ``pd.tseries.util.isleapyear`` has been removed (deprecated since v0.19). Use ``.is_leap_year`` property in Datetime-likes instead (:issue:`18370`)
8081

8182
.. _whatsnew_0220.performance:
8283

pandas/tests/reshape/test_pivot.py

Lines changed: 44 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from pandas.core.reshape.pivot import pivot_table, crosstab
1414
from pandas.compat import range, product
1515
import pandas.util.testing as tm
16-
from pandas.tseries.util import pivot_annual, isleapyear
1716
from pandas.api.types import CategoricalDtype as CDT
1817

1918

@@ -891,6 +890,40 @@ def test_pivot_dtaccessor(self):
891890
index=['X', 'Y'], columns=exp_col)
892891
tm.assert_frame_equal(result, expected)
893892

893+
def test_daily(self):
894+
rng = date_range('1/1/2000', '12/31/2004', freq='D')
895+
ts = Series(np.random.randn(len(rng)), index=rng)
896+
897+
annual = pivot_table(DataFrame(ts), index=ts.index.year,
898+
columns=ts.index.dayofyear)
899+
annual.columns = annual.columns.droplevel(0)
900+
901+
doy = np.asarray(ts.index.dayofyear)
902+
903+
for i in range(1, 367):
904+
subset = ts[doy == i]
905+
subset.index = subset.index.year
906+
907+
result = annual[i].dropna()
908+
tm.assert_series_equal(result, subset, check_names=False)
909+
assert result.name == i
910+
911+
def test_monthly(self):
912+
rng = date_range('1/1/2000', '12/31/2004', freq='M')
913+
ts = Series(np.random.randn(len(rng)), index=rng)
914+
915+
annual = pivot_table(pd.DataFrame(ts), index=ts.index.year,
916+
columns=ts.index.month)
917+
annual.columns = annual.columns.droplevel(0)
918+
919+
month = ts.index.month
920+
for i in range(1, 13):
921+
subset = ts[month == i]
922+
subset.index = subset.index.year
923+
result = annual[i].dropna()
924+
tm.assert_series_equal(result, subset, check_names=False)
925+
assert result.name == i
926+
894927
def test_pivot_table_with_iterator_values(self):
895928
# GH 12017
896929
aggs = {'D': 'sum', 'E': 'mean'}
@@ -1048,6 +1081,16 @@ def test_pivot_table_not_series(self):
10481081

10491082
tm.assert_frame_equal(result, expected)
10501083

1084+
def test_pivot_margins_name_unicode(self):
1085+
# issue #13292
1086+
greek = u'\u0394\u03bf\u03ba\u03b9\u03bc\u03ae'
1087+
frame = pd.DataFrame({'foo': [1, 2, 3]})
1088+
table = pd.pivot_table(frame, index=['foo'], aggfunc=len, margins=True,
1089+
margins_name=greek)
1090+
index = pd.Index([1, 2, 3, greek], dtype='object', name='foo')
1091+
expected = pd.DataFrame(index=index)
1092+
tm.assert_frame_equal(table, expected)
1093+
10511094

10521095
class TestCrosstab(object):
10531096

@@ -1525,116 +1568,3 @@ def test_crosstab_dup_index_names(self):
15251568
index=expected_index,
15261569
columns=expected_index)
15271570
tm.assert_frame_equal(result, expected)
1528-
1529-
1530-
class TestPivotAnnual(object):
1531-
"""
1532-
New pandas of scikits.timeseries pivot_annual
1533-
"""
1534-
1535-
def test_daily(self):
1536-
rng = date_range('1/1/2000', '12/31/2004', freq='D')
1537-
ts = Series(np.random.randn(len(rng)), index=rng)
1538-
1539-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
1540-
annual = pivot_annual(ts, 'D')
1541-
1542-
doy = np.asarray(ts.index.dayofyear)
1543-
1544-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
1545-
doy[(~isleapyear(ts.index.year)) & (doy >= 60)] += 1
1546-
1547-
for i in range(1, 367):
1548-
subset = ts[doy == i]
1549-
subset.index = [x.year for x in subset.index]
1550-
1551-
result = annual[i].dropna()
1552-
tm.assert_series_equal(result, subset, check_names=False)
1553-
assert result.name == i
1554-
1555-
# check leap days
1556-
leaps = ts[(ts.index.month == 2) & (ts.index.day == 29)]
1557-
day = leaps.index.dayofyear[0]
1558-
leaps.index = leaps.index.year
1559-
leaps.name = 60
1560-
tm.assert_series_equal(annual[day].dropna(), leaps)
1561-
1562-
def test_hourly(self):
1563-
rng_hourly = date_range('1/1/1994', periods=(18 * 8760 + 4 * 24),
1564-
freq='H')
1565-
data_hourly = np.random.randint(100, 350, rng_hourly.size)
1566-
ts_hourly = Series(data_hourly, index=rng_hourly)
1567-
1568-
grouped = ts_hourly.groupby(ts_hourly.index.year)
1569-
hoy = grouped.apply(lambda x: x.reset_index(drop=True))
1570-
hoy = hoy.index.droplevel(0).values
1571-
1572-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
1573-
hoy[~isleapyear(ts_hourly.index.year) & (hoy >= 1416)] += 24
1574-
hoy += 1
1575-
1576-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
1577-
annual = pivot_annual(ts_hourly)
1578-
1579-
ts_hourly = ts_hourly.astype(float)
1580-
for i in [1, 1416, 1417, 1418, 1439, 1440, 1441, 8784]:
1581-
subset = ts_hourly[hoy == i]
1582-
subset.index = [x.year for x in subset.index]
1583-
1584-
result = annual[i].dropna()
1585-
tm.assert_series_equal(result, subset, check_names=False)
1586-
assert result.name == i
1587-
1588-
leaps = ts_hourly[(ts_hourly.index.month == 2) & (
1589-
ts_hourly.index.day == 29) & (ts_hourly.index.hour == 0)]
1590-
hour = leaps.index.dayofyear[0] * 24 - 23
1591-
leaps.index = leaps.index.year
1592-
leaps.name = 1417
1593-
tm.assert_series_equal(annual[hour].dropna(), leaps)
1594-
1595-
def test_weekly(self):
1596-
pass
1597-
1598-
def test_monthly(self):
1599-
rng = date_range('1/1/2000', '12/31/2004', freq='M')
1600-
ts = Series(np.random.randn(len(rng)), index=rng)
1601-
1602-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
1603-
annual = pivot_annual(ts, 'M')
1604-
1605-
month = ts.index.month
1606-
for i in range(1, 13):
1607-
subset = ts[month == i]
1608-
subset.index = [x.year for x in subset.index]
1609-
result = annual[i].dropna()
1610-
tm.assert_series_equal(result, subset, check_names=False)
1611-
assert result.name == i
1612-
1613-
def test_period_monthly(self):
1614-
pass
1615-
1616-
def test_period_daily(self):
1617-
pass
1618-
1619-
def test_period_weekly(self):
1620-
pass
1621-
1622-
def test_isleapyear_deprecate(self):
1623-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
1624-
assert isleapyear(2000)
1625-
1626-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
1627-
assert not isleapyear(2001)
1628-
1629-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
1630-
assert isleapyear(2004)
1631-
1632-
def test_pivot_margins_name_unicode(self):
1633-
# issue #13292
1634-
greek = u'\u0394\u03bf\u03ba\u03b9\u03bc\u03ae'
1635-
frame = pd.DataFrame({'foo': [1, 2, 3]})
1636-
table = pd.pivot_table(frame, index=['foo'], aggfunc=len, margins=True,
1637-
margins_name=greek)
1638-
index = pd.Index([1, 2, 3, greek], dtype='object', name='foo')
1639-
expected = pd.DataFrame(index=index)
1640-
tm.assert_frame_equal(table, expected)

pandas/tseries/util.py

Lines changed: 0 additions & 104 deletions
This file was deleted.

0 commit comments

Comments
 (0)