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: pd.TimeGrouper #26477

Merged
merged 3 commits into from
May 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.25.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ Removal of prior version deprecations/changes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- Removed ``Panel`` (:issue:`25047`, :issue:`25191`, :issue:`25231`)
-
-
- Removed previously deprecated ``TimeGrouper`` (:issue:`16942`)
-

.. _whatsnew_0250.performance:
Expand Down
2 changes: 1 addition & 1 deletion pandas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
to_numeric, to_datetime, to_timedelta,

# misc
np, TimeGrouper, Grouper, factorize, unique, value_counts,
np, Grouper, factorize, unique, value_counts,
array, Categorical, set_eng_float_format, Series, DataFrame,
Panel)

Expand Down
12 changes: 0 additions & 12 deletions pandas/core/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,3 @@
from pandas.tseries.offsets import DateOffset
from pandas.core.tools.datetimes import to_datetime
from pandas.core.tools.timedeltas import to_timedelta


# Deprecation: xref gh-16747
class TimeGrouper:

def __new__(cls, *args, **kwargs):
from pandas.core.resample import TimeGrouper
import warnings
warnings.warn("pd.TimeGrouper is deprecated and will be removed; "
"Please use pd.Grouper(freq=...)",
FutureWarning, stacklevel=2)
return TimeGrouper(*args, **kwargs)
13 changes: 1 addition & 12 deletions pandas/tests/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class TestPDApi(Base):
]

# these are already deprecated; awaiting removal
deprecated_classes = ['TimeGrouper', 'Panel']
deprecated_classes = ['Panel']

# these should be deprecated in the future
deprecated_classes_in_future = []
Expand Down Expand Up @@ -132,17 +132,6 @@ def test_testing(self):
self.check(testing, self.funcs)


class TestTopLevelDeprecations:

# top-level API deprecations
# GH 13790

def test_TimeGrouper(self):
with tm.assert_produces_warning(FutureWarning,
check_stacklevel=False):
pd.TimeGrouper(freq='D')


class TestCDateRange:

def test_deprecation_cdaterange(self):
Expand Down
7 changes: 3 additions & 4 deletions pandas/tests/groupby/test_timegrouper.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import pandas as pd
from pandas import DataFrame, Index, MultiIndex, Series, Timestamp, date_range
from pandas.core.groupby.grouper import Grouper
from pandas.core.groupby.ops import BinGrouper
from pandas.util import testing as tm
from pandas.util.testing import assert_frame_equal, assert_series_equal
Expand Down Expand Up @@ -365,10 +366,8 @@ def sumfunc_value(x):
return x.value.sum()

expected = df.groupby(pd.Grouper(key='date')).apply(sumfunc_value)
Copy link
Contributor

Choose a reason for hiding this comment

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

can you change these to use Grouper (here and below)

with tm.assert_produces_warning(FutureWarning,
check_stacklevel=False):
result = (df_dt.groupby(pd.TimeGrouper(freq='M', key='date'))
.apply(sumfunc_value))
result = (df_dt.groupby(Grouper(freq='M', key='date'))
.apply(sumfunc_value))
assert_series_equal(result.reset_index(drop=True),
expected.reset_index(drop=True))

Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/resample/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import pandas as pd
from pandas import DataFrame, Series
from pandas.core.groupby.groupby import DataError
from pandas.core.groupby.grouper import Grouper
from pandas.core.indexes.datetimes import date_range
from pandas.core.indexes.period import PeriodIndex, period_range
from pandas.core.indexes.timedeltas import TimedeltaIndex, timedelta_range
from pandas.core.resample import TimeGrouper
import pandas.util.testing as tm
from pandas.util.testing import (
assert_almost_equal, assert_frame_equal, assert_index_equal,
Expand Down Expand Up @@ -214,7 +214,7 @@ def test_apply_to_empty_series(empty_series):
def test_resampler_is_iterable(series):
# GH 15314
freq = 'H'
tg = TimeGrouper(freq, convention='start')
tg = Grouper(freq=freq, convention='start')
grouped = series.groupby(tg)
resampled = series.resample(freq)
for (rk, rv), (gk, gv) in zip(resampled, grouped):
Expand Down
14 changes: 7 additions & 7 deletions pandas/tests/resample/test_datetime_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

import pandas as pd
from pandas import DataFrame, Series, Timedelta, Timestamp, isna, notna
from pandas.core.groupby.grouper import Grouper
from pandas.core.indexes.datetimes import date_range
from pandas.core.indexes.period import Period, period_range
from pandas.core.resample import (
DatetimeIndex, TimeGrouper, _get_timestamp_range_edges)
from pandas.core.resample import DatetimeIndex, _get_timestamp_range_edges
import pandas.util.testing as tm
from pandas.util.testing import (
assert_almost_equal, assert_frame_equal, assert_series_equal)
Expand Down Expand Up @@ -42,15 +42,15 @@ def test_custom_grouper(index):
dti = index
s = Series(np.array([1] * len(dti)), index=dti, dtype='int64')

b = TimeGrouper(Minute(5))
b = Grouper(freq=Minute(5))
g = s.groupby(b)

# check all cython functions work
funcs = ['add', 'mean', 'prod', 'ohlc', 'min', 'max', 'var']
for f in funcs:
g._cython_agg_general(f)

b = TimeGrouper(Minute(5), closed='right', label='right')
b = Grouper(freq=Minute(5), closed='right', label='right')
g = s.groupby(b)
# check all cython functions work
funcs = ['add', 'mean', 'prod', 'ohlc', 'min', 'max', 'var']
Expand Down Expand Up @@ -116,7 +116,7 @@ def test_resample_integerarray():
def test_resample_basic_grouper(series):
s = series
result = s.resample('5Min').last()
grouper = TimeGrouper(Minute(5), closed='left', label='left')
grouper = Grouper(freq=Minute(5), closed='left', label='left')
expected = s.groupby(grouper).agg(lambda x: x[-1])
assert_series_equal(result, expected)

Expand Down Expand Up @@ -373,7 +373,7 @@ def test_resample_upsampling_picked_but_not_correct():
def test_resample_frame_basic():
df = tm.makeTimeDataFrame()

b = TimeGrouper('M')
b = Grouper(freq='M')
g = df.groupby(b)

# check all cython functions work
Expand Down Expand Up @@ -521,7 +521,7 @@ def test_nearest_upsample_with_limit():
def test_resample_ohlc(series):
s = series

grouper = TimeGrouper(Minute(5))
grouper = Grouper(freq=Minute(5))
expect = s.groupby(grouper).agg(lambda x: x[-1])
result = s.resample('5Min').ohlc()

Expand Down
24 changes: 10 additions & 14 deletions pandas/tests/resample/test_time_grouper.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import pandas as pd
from pandas import DataFrame, Series
from pandas.core.groupby.grouper import Grouper
from pandas.core.indexes.datetimes import date_range
from pandas.core.resample import TimeGrouper
import pandas.util.testing as tm
from pandas.util.testing import assert_frame_equal, assert_series_equal

Expand All @@ -16,9 +16,7 @@


def test_apply():
with tm.assert_produces_warning(FutureWarning,
check_stacklevel=False):
grouper = pd.TimeGrouper(freq='A', label='right', closed='right')
grouper = Grouper(freq='A', label='right', closed='right')

grouped = test_series.groupby(grouper)

Expand All @@ -38,9 +36,7 @@ def test_count():

expected = test_series.groupby(lambda x: x.year).count()

with tm.assert_produces_warning(FutureWarning,
check_stacklevel=False):
grouper = pd.TimeGrouper(freq='A', label='right', closed='right')
grouper = Grouper(freq='A', label='right', closed='right')
result = test_series.groupby(grouper).count()
expected.index = result.index
assert_series_equal(result, expected)
Expand All @@ -64,7 +60,7 @@ def test_apply_iteration():
N = 1000
ind = pd.date_range(start="2000-01-01", freq="D", periods=N)
df = DataFrame({'open': 1, 'close': 2}, index=ind)
tg = TimeGrouper('M')
tg = Grouper(freq='M')

_, grouper, _ = tg._get_grouper(df)

Expand Down Expand Up @@ -93,7 +89,7 @@ def test_fails_on_no_datetime_index(name, func):
msg = ("Only valid with DatetimeIndex, TimedeltaIndex "
"or PeriodIndex, but got an instance of '{}'".format(name))
with pytest.raises(TypeError, match=msg):
df.groupby(TimeGrouper('D'))
df.groupby(Grouper(freq='D'))


def test_aaa_group_order():
Expand All @@ -105,7 +101,7 @@ def test_aaa_group_order():
df['key'] = [datetime(2013, 1, 1), datetime(2013, 1, 2),
datetime(2013, 1, 3), datetime(2013, 1, 4),
datetime(2013, 1, 5)] * 4
grouped = df.groupby(TimeGrouper(key='key', freq='D'))
grouped = df.groupby(Grouper(key='key', freq='D'))

tm.assert_frame_equal(grouped.get_group(datetime(2013, 1, 1)),
df[::5])
Expand Down Expand Up @@ -135,7 +131,7 @@ def test_aggregate_normal(resample_method):
datetime(2013, 1, 5)] * 4

normal_grouped = normal_df.groupby('key')
dt_grouped = dt_df.groupby(TimeGrouper(key='key', freq='D'))
dt_grouped = dt_df.groupby(Grouper(key='key', freq='D'))

expected = getattr(normal_grouped, resample_method)()
dt_result = getattr(dt_grouped, resample_method)()
Expand Down Expand Up @@ -195,7 +191,7 @@ def test_aggregate_with_nat(func, fill_value):
datetime(2013, 1, 4), datetime(2013, 1, 5)] * 4

normal_grouped = normal_df.groupby('key')
dt_grouped = dt_df.groupby(TimeGrouper(key='key', freq='D'))
dt_grouped = dt_df.groupby(Grouper(key='key', freq='D'))

normal_result = getattr(normal_grouped, func)()
dt_result = getattr(dt_grouped, func)()
Expand All @@ -222,7 +218,7 @@ def test_aggregate_with_nat_size():
datetime(2013, 1, 4), datetime(2013, 1, 5)] * 4

normal_grouped = normal_df.groupby('key')
dt_grouped = dt_df.groupby(TimeGrouper(key='key', freq='D'))
dt_grouped = dt_df.groupby(Grouper(key='key', freq='D'))

normal_result = normal_grouped.size()
dt_result = dt_grouped.size()
Expand All @@ -238,7 +234,7 @@ def test_aggregate_with_nat_size():

def test_repr():
# GH18203
result = repr(TimeGrouper(key='A', freq='H'))
result = repr(Grouper(key='A', freq='H'))
expected = ("TimeGrouper(key='A', freq=<Hour>, axis=0, sort=True, "
"closed='left', label='left', how='mean', "
"convention='e', base=0)")
Expand Down