Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLN: remove tseries.util.pivot_annual/isleapyear #18370

Merged
merged 2 commits into from
Nov 22, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion doc/source/whatsnew/v0.22.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ Removal of prior version deprecations/changes

- 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`)
- The ``levels`` and ``labels`` attributes of a ``MultiIndex`` can no longer be set directly (:issue:`4039`).
-
- ``pd.tseries.util.pivot_annual`` has been removed (deprecated since v0.19). Use ``pivot_table`` instead (:issue:`18370`)
- ``pd.tseries.util.isleapyear`` has been removed (deprecated since v0.19). Use ``.is_leap_year`` property in Datetime-likes instead (:issue:`18370`)

.. _whatsnew_0220.performance:

Expand Down
124 changes: 10 additions & 114 deletions pandas/tests/reshape/test_pivot.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from pandas.core.reshape.pivot import pivot_table, crosstab
from pandas.compat import range, product
import pandas.util.testing as tm
from pandas.tseries.util import pivot_annual, isleapyear
from pandas.api.types import CategoricalDtype as CDT


Expand Down Expand Up @@ -1048,6 +1047,16 @@ def test_pivot_table_not_series(self):

tm.assert_frame_equal(result, expected)

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


class TestCrosstab(object):

Expand Down Expand Up @@ -1525,116 +1534,3 @@ def test_crosstab_dup_index_names(self):
index=expected_index,
columns=expected_index)
tm.assert_frame_equal(result, expected)


class TestPivotAnnual(object):
"""
New pandas of scikits.timeseries pivot_annual
"""

def test_daily(self):
rng = date_range('1/1/2000', '12/31/2004', freq='D')
ts = Series(np.random.randn(len(rng)), index=rng)

with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
annual = pivot_annual(ts, 'D')

doy = np.asarray(ts.index.dayofyear)

with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
doy[(~isleapyear(ts.index.year)) & (doy >= 60)] += 1

for i in range(1, 367):
subset = ts[doy == i]
subset.index = [x.year for x in subset.index]

result = annual[i].dropna()
tm.assert_series_equal(result, subset, check_names=False)
assert result.name == i

# check leap days
leaps = ts[(ts.index.month == 2) & (ts.index.day == 29)]
day = leaps.index.dayofyear[0]
leaps.index = leaps.index.year
leaps.name = 60
tm.assert_series_equal(annual[day].dropna(), leaps)

def test_hourly(self):
rng_hourly = date_range('1/1/1994', periods=(18 * 8760 + 4 * 24),
freq='H')
data_hourly = np.random.randint(100, 350, rng_hourly.size)
ts_hourly = Series(data_hourly, index=rng_hourly)

grouped = ts_hourly.groupby(ts_hourly.index.year)
hoy = grouped.apply(lambda x: x.reset_index(drop=True))
hoy = hoy.index.droplevel(0).values
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

anything worthy of a test for these? eg maybe see if something similar using pivot_table (if not can u construct a test)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A point is that pivot_table requires dataframes, and pivot_annual works on series [that need to have a DatetimeIndex]. So pivot_table is strictly speaking not doing the same as pivot_annual.

A deeper second issue is that pivot_annual dayofyear number 60 is always febr. 29, while for other pandas date functionality day 60 switches between febr. 29 and 1.mars , depending on whether we're not having a leap year or not.

I'll take a look into if something can be moved. However, do you not think that such date functionality is checked other places, i..e. we duplicate datetime tests by adding them to TestPivotTable? See for example TestPivotTable.test_pivot_timegrouper, line 716 for some date pivot_table tests.


with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
hoy[~isleapyear(ts_hourly.index.year) & (hoy >= 1416)] += 24
hoy += 1

with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
annual = pivot_annual(ts_hourly)

ts_hourly = ts_hourly.astype(float)
for i in [1, 1416, 1417, 1418, 1439, 1440, 1441, 8784]:
subset = ts_hourly[hoy == i]
subset.index = [x.year for x in subset.index]

result = annual[i].dropna()
tm.assert_series_equal(result, subset, check_names=False)
assert result.name == i

leaps = ts_hourly[(ts_hourly.index.month == 2) & (
ts_hourly.index.day == 29) & (ts_hourly.index.hour == 0)]
hour = leaps.index.dayofyear[0] * 24 - 23
leaps.index = leaps.index.year
leaps.name = 1417
tm.assert_series_equal(annual[hour].dropna(), leaps)

def test_weekly(self):
pass

def test_monthly(self):
rng = date_range('1/1/2000', '12/31/2004', freq='M')
ts = Series(np.random.randn(len(rng)), index=rng)

with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
annual = pivot_annual(ts, 'M')

month = ts.index.month
for i in range(1, 13):
subset = ts[month == i]
subset.index = [x.year for x in subset.index]
result = annual[i].dropna()
tm.assert_series_equal(result, subset, check_names=False)
assert result.name == i

def test_period_monthly(self):
pass

def test_period_daily(self):
pass

def test_period_weekly(self):
pass

def test_isleapyear_deprecate(self):
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
assert isleapyear(2000)

with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
assert not isleapyear(2001)

with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
assert isleapyear(2004)

def test_pivot_margins_name_unicode(self):
# issue #13292
greek = u'\u0394\u03bf\u03ba\u03b9\u03bc\u03ae'
frame = pd.DataFrame({'foo': [1, 2, 3]})
table = pd.pivot_table(frame, index=['foo'], aggfunc=len, margins=True,
margins_name=greek)
index = pd.Index([1, 2, 3, greek], dtype='object', name='foo')
expected = pd.DataFrame(index=index)
tm.assert_frame_equal(table, expected)
104 changes: 0 additions & 104 deletions pandas/tseries/util.py

This file was deleted.