From 236ff13d60584b39b54f6f900c4ef6a7db462271 Mon Sep 17 00:00:00 2001 From: Vamsi Verma Date: Fri, 14 Oct 2022 21:08:19 +0000 Subject: [PATCH 1/7] pylint: disable access-member-before-definition for loffset --- pandas/core/resample.py | 1 + pyproject.toml | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/resample.py b/pandas/core/resample.py index f821f8c7b6bd5..25663f08d0ebc 100644 --- a/pandas/core/resample.py +++ b/pandas/core/resample.py @@ -494,6 +494,7 @@ def _apply_loffset(self, result): result : Series or DataFrame the result of resample """ + # pylint: disable=access-member-before-definition # error: Cannot determine type of 'loffset' needs_offset = ( isinstance( diff --git a/pyproject.toml b/pyproject.toml index 00467a5dfe206..313c7ebcea676 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -62,7 +62,6 @@ disable = [ "R", "W", "abstract-class-instantiated", - "access-member-before-definition", "import-error", "invalid-repr-returned", "invalid-unary-operand-type", From 5b601f990f4cdf8cad9fbece0e55148372a15943 Mon Sep 17 00:00:00 2001 From: Vamsi Verma Date: Wed, 19 Oct 2022 18:50:19 +0000 Subject: [PATCH 2/7] remove deprecated loffset and base args --- doc/source/whatsnew/v2.0.0.rst | 1 + pandas/core/frame.py | 4 - pandas/core/generic.py | 42 ---- pandas/core/groupby/grouper.py | 68 ------ pandas/core/resample.py | 63 ----- pandas/core/series.py | 4 - pandas/tests/resample/test_deprecated.py | 278 +---------------------- 7 files changed, 2 insertions(+), 458 deletions(-) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 89cfa8c580523..76c2a77ce417d 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -258,6 +258,7 @@ Groupby/resample/rolling - Bug in :meth:`DataFrameGroupBy.sample` raises ``ValueError`` when the object is empty (:issue:`48459`) - Bug in :meth:`Series.groupby` raises ``ValueError`` when an entry of the index is equal to the name of the index (:issue:`48567`) - Bug in :meth:`DataFrameGroupBy.resample` produces inconsistent results when passing empty DataFrame (:issue:`47705`) +- Removed the previously deprecated ``base`` and ``loffset`` arguments from :meth:`pandas.DataFrame.resample`, :meth:`pandas.Series.resample` and :class:`pandas.Grouper`. Use ``offset`` or ``origin`` instead (:issue:`31809`) - Reshaping diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 8b6235374bed0..53bfa17c98170 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -11432,8 +11432,6 @@ def resample( label: str | None = None, convention: str = "start", kind: str | None = None, - loffset=None, - base: int | None = None, on: Level = None, level: Level = None, origin: str | TimestampConvertibleTypes = "start_day", @@ -11447,8 +11445,6 @@ def resample( label=label, convention=convention, kind=kind, - loffset=loffset, - base=base, on=on, level=level, origin=origin, diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 23ada120505d5..5bd79a20c1e43 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -8484,8 +8484,6 @@ def resample( label: str | None = None, convention: str = "start", kind: str | None = None, - loffset=None, - base: int | None = None, on: Level = None, level: Level = None, origin: str | TimestampConvertibleTypes = "start_day", @@ -8523,20 +8521,6 @@ def resample( Pass 'timestamp' to convert the resulting index to a `DateTimeIndex` or 'period' to convert it to a `PeriodIndex`. By default the input representation is retained. - loffset : timedelta, default None - Adjust the resampled time labels. - - .. deprecated:: 1.1.0 - You should add the loffset to the `df.index` after the resample. - See below. - - base : int, default 0 - For frequencies that evenly subdivide 1 day, the "origin" of the - aggregated intervals. For example, for '5min' frequency, base could - range from 0 through 4. Defaults to 0. - - .. deprecated:: 1.1.0 - The new arguments that you should use are 'offset' or 'origin'. on : str, optional For a DataFrame, column to use instead of index for resampling. @@ -8873,30 +8857,6 @@ def resample( 2000-10-02 00:29:00 45 Freq: 17T, dtype: int64 - To replace the use of the deprecated `base` argument, you can now use `offset`, - in this example it is equivalent to have `base=2`: - - >>> ts.resample('17min', offset='2min').sum() - 2000-10-01 23:16:00 0 - 2000-10-01 23:33:00 9 - 2000-10-01 23:50:00 36 - 2000-10-02 00:07:00 39 - 2000-10-02 00:24:00 24 - Freq: 17T, dtype: int64 - - To replace the use of the deprecated `loffset` argument: - - >>> from pandas.tseries.frequencies import to_offset - >>> loffset = '19min' - >>> ts_out = ts.resample('17min').sum() - >>> ts_out.index = ts_out.index + to_offset(loffset) - >>> ts_out - 2000-10-01 23:33:00 0 - 2000-10-01 23:50:00 9 - 2000-10-02 00:07:00 21 - 2000-10-02 00:24:00 54 - 2000-10-02 00:41:00 24 - Freq: 17T, dtype: int64 """ from pandas.core.resample import get_resampler @@ -8908,9 +8868,7 @@ def resample( closed=closed, axis=axis, kind=kind, - loffset=loffset, convention=convention, - base=base, key=on, level=level, origin=origin, diff --git a/pandas/core/groupby/grouper.py b/pandas/core/groupby/grouper.py index dc7679a1744ea..745a5434ee61b 100644 --- a/pandas/core/groupby/grouper.py +++ b/pandas/core/groupby/grouper.py @@ -11,7 +11,6 @@ Iterator, final, ) -import warnings import numpy as np @@ -23,7 +22,6 @@ ) from pandas.errors import InvalidIndexError from pandas.util._decorators import cache_readonly -from pandas.util._exceptions import find_stack_level from pandas.core.dtypes.common import ( is_categorical_dtype, @@ -89,23 +87,6 @@ class Grouper: Only when `freq` parameter is passed. convention : {'start', 'end', 'e', 's'} If grouper is PeriodIndex and `freq` parameter is passed. - base : int, default 0 - Only when `freq` parameter is passed. - For frequencies that evenly subdivide 1 day, the "origin" of the - aggregated intervals. For example, for '5min' frequency, base could - range from 0 through 4. Defaults to 0. - - .. deprecated:: 1.1.0 - The new arguments that you should use are 'offset' or 'origin'. - - loffset : str, DateOffset, timedelta object - Only when `freq` parameter is passed. - - .. deprecated:: 1.1.0 - loffset is only working for ``.resample(...)`` and not for - Grouper (:issue:`28302`). - However, loffset is also deprecated for ``.resample(...)`` - See: :class:`DataFrame.resample` origin : Timestamp or str, default 'start_day' The timestamp on which to adjust the grouping. The timezone of origin must @@ -269,7 +250,6 @@ def __new__(cls, *args, **kwargs): if kwargs.get("freq") is not None: from pandas.core.resample import TimeGrouper - _check_deprecated_resample_kwargs(kwargs, origin=cls) cls = TimeGrouper return super().__new__(cls) @@ -950,51 +930,3 @@ def _convert_grouper(axis: Index, grouper): return grouper else: return grouper - - -def _check_deprecated_resample_kwargs(kwargs, origin) -> None: - """ - Check for use of deprecated parameters in ``resample`` and related functions. - - Raises the appropriate warnings if these parameters are detected. - Only sets an approximate ``stacklevel`` for the warnings (see #37603, #36629). - - Parameters - ---------- - kwargs : dict - Dictionary of keyword arguments to check for deprecated parameters. - origin : object - From where this function is being called; either Grouper or TimeGrouper. Used - to determine an approximate stacklevel. - """ - # Deprecation warning of `base` and `loffset` since v1.1.0: - # we are raising the warning here to be able to set the `stacklevel` - # properly since we need to raise the `base` and `loffset` deprecation - # warning from three different cases: - # core/generic.py::NDFrame.resample - # core/groupby/groupby.py::GroupBy.resample - # core/groupby/grouper.py::Grouper - # raising these warnings from TimeGrouper directly would fail the test: - # tests/resample/test_deprecated.py::test_deprecating_on_loffset_and_base - - if kwargs.get("base", None) is not None: - warnings.warn( - "'base' in .resample() and in Grouper() is deprecated.\n" - "The new arguments that you should use are 'offset' or 'origin'.\n" - '\n>>> df.resample(freq="3s", base=2)\n' - "\nbecomes:\n" - '\n>>> df.resample(freq="3s", offset="2s")\n', - FutureWarning, - stacklevel=find_stack_level(), - ) - if kwargs.get("loffset", None) is not None: - warnings.warn( - "'loffset' in .resample() and in Grouper() is deprecated.\n" - '\n>>> df.resample(freq="3s", loffset="8H")\n' - "\nbecomes:\n" - "\n>>> from pandas.tseries.frequencies import to_offset" - '\n>>> df = df.resample(freq="3s").mean()' - '\n>>> df.index = df.index.to_timestamp() + to_offset("8H")\n', - FutureWarning, - stacklevel=find_stack_level(), - ) diff --git a/pandas/core/resample.py b/pandas/core/resample.py index 25663f08d0ebc..84c4766220f85 100644 --- a/pandas/core/resample.py +++ b/pandas/core/resample.py @@ -92,7 +92,6 @@ is_superperiod, ) from pandas.tseries.offsets import ( - DateOffset, Day, Nano, Tick, @@ -142,7 +141,6 @@ class Resampler(BaseGroupBy, PandasObject): "closed", "label", "convention", - "loffset", "kind", "origin", "offset", @@ -362,7 +360,6 @@ def aggregate(self, func=None, *args, **kwargs): how = func result = self._groupby_and_aggregate(how, *args, **kwargs) - result = self._apply_loffset(result) return result agg = aggregate @@ -479,39 +476,8 @@ def _groupby_and_aggregate(self, how, *args, **kwargs): # try to evaluate result = grouped.apply(how, *args, **kwargs) - result = self._apply_loffset(result) return self._wrap_result(result) - def _apply_loffset(self, result): - """ - If loffset is set, offset the result index. - - This is NOT an idempotent routine, it will be applied - exactly once to the result. - - Parameters - ---------- - result : Series or DataFrame - the result of resample - """ - # pylint: disable=access-member-before-definition - # error: Cannot determine type of 'loffset' - needs_offset = ( - isinstance( - self.loffset, # type: ignore[has-type] - (DateOffset, timedelta, np.timedelta64), - ) - and isinstance(result.index, DatetimeIndex) - and len(result.index) > 0 - ) - - if needs_offset: - # error: Cannot determine type of 'loffset' - result.index = result.index + self.loffset # type: ignore[has-type] - - self.loffset = None - return result - def _get_resampler_for_grouping(self, groupby, key=None): """ Return the correct class for resampling with groupby. @@ -1349,7 +1315,6 @@ def _downsample(self, how, **kwargs): # we want to call the actual grouper method here result = obj.groupby(self.grouper, axis=self.axis).aggregate(how, **kwargs) - result = self._apply_loffset(result) return self._wrap_result(result) def _adjust_binner_for_upsample(self, binner): @@ -1407,7 +1372,6 @@ def _upsample(self, method, limit=None, fill_value=None): res_index, method=method, limit=limit, fill_value=fill_value ) - result = self._apply_loffset(result) return self._wrap_result(result) def _wrap_result(self, result): @@ -1452,11 +1416,6 @@ def _convert_obj(self, obj: NDFrameT) -> NDFrameT: ) raise NotImplementedError(msg) - if self.loffset is not None: - # Cannot apply loffset/timedelta to PeriodIndex -> convert to - # timestamps - self.kind = "timestamp" - # convert to timestamp if self.kind == "timestamp": obj = obj.to_timestamp(how=self.convention) @@ -1617,7 +1576,6 @@ class TimeGrouper(Grouper): "closed", "label", "how", - "loffset", "kind", "convention", "origin", @@ -1635,10 +1593,8 @@ def __init__( axis: Axis = 0, fill_method=None, limit=None, - loffset=None, kind: str | None = None, convention: Literal["start", "end", "e", "s"] | None = None, - base: int | None = None, origin: Literal["epoch", "start", "start_day", "end", "end_day"] | TimestampConvertibleTypes = "start_day", offset: TimedeltaConvertibleTypes | None = None, @@ -1718,22 +1674,6 @@ def __init__( # always sort time groupers kwargs["sort"] = True - # Handle deprecated arguments since v1.1.0 of `base` and `loffset` (GH #31809) - if base is not None and offset is not None: - raise ValueError("'offset' and 'base' cannot be present at the same time") - - if base and isinstance(freq, Tick): - # this conversion handle the default behavior of base and the - # special case of GH #10530. Indeed in case when dealing with - # a TimedeltaIndex base was treated as a 'pure' offset even though - # the default behavior of base was equivalent of a modulo on - # freq_nanos. - self.offset = Timedelta(base * freq.nanos // freq.n) - - if isinstance(loffset, str): - loffset = to_offset(loffset) - self.loffset = loffset - super().__init__(freq=freq, axis=axis, **kwargs) def _get_resampler(self, obj, kind=None): @@ -1894,9 +1834,6 @@ def _get_time_delta_bins(self, ax: TimedeltaIndex): if self.offset: # GH 10530 & 31809 labels += self.offset - if self.loffset: - # GH 33498 - labels += self.loffset return binner, bins, labels diff --git a/pandas/core/series.py b/pandas/core/series.py index f4b59266e2b91..e0a8cb7afe3fe 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -5879,8 +5879,6 @@ def resample( label: str | None = None, convention: str = "start", kind: str | None = None, - loffset=None, - base: int | None = None, on: Level = None, level: Level = None, origin: str | TimestampConvertibleTypes = "start_day", @@ -5894,8 +5892,6 @@ def resample( label=label, convention=convention, kind=kind, - loffset=loffset, - base=base, on=on, level=level, origin=origin, diff --git a/pandas/tests/resample/test_deprecated.py b/pandas/tests/resample/test_deprecated.py index 126ca05ca1546..6002a128082e9 100644 --- a/pandas/tests/resample/test_deprecated.py +++ b/pandas/tests/resample/test_deprecated.py @@ -1,283 +1,7 @@ -from datetime import ( - datetime, - timedelta, -) - -import numpy as np -import pytest - import pandas as pd -from pandas import ( - DataFrame, - Series, -) +from pandas import Series import pandas._testing as tm from pandas.core.indexes.datetimes import date_range -from pandas.core.indexes.period import ( - PeriodIndex, - period_range, -) -from pandas.core.indexes.timedeltas import timedelta_range - -from pandas.tseries.offsets import ( - BDay, - Minute, -) - -DATE_RANGE = (date_range, "dti", datetime(2005, 1, 1), datetime(2005, 1, 10)) -PERIOD_RANGE = (period_range, "pi", datetime(2005, 1, 1), datetime(2005, 1, 10)) -TIMEDELTA_RANGE = (timedelta_range, "tdi", "1 day", "10 day") - -all_ts = pytest.mark.parametrize( - "_index_factory,_series_name,_index_start,_index_end", - [DATE_RANGE, PERIOD_RANGE, TIMEDELTA_RANGE], -) - - -@pytest.fixture() -def _index_factory(): - return period_range - - -@pytest.fixture -def create_index(_index_factory): - def _create_index(*args, **kwargs): - """return the _index_factory created using the args, kwargs""" - return _index_factory(*args, **kwargs) - - return _create_index - - -# new test to check that all FutureWarning are triggered -def test_deprecating_on_loffset_and_base(): - # GH 31809 - - idx = date_range("2001-01-01", periods=4, freq="T") - df = DataFrame(data=4 * [range(2)], index=idx, columns=["a", "b"]) - - with tm.assert_produces_warning(FutureWarning): - pd.Grouper(freq="10s", base=0) - with tm.assert_produces_warning(FutureWarning): - pd.Grouper(freq="10s", loffset="0s") - - # not checking the stacklevel for .groupby().resample() because it's complicated to - # reconcile it with the stacklevel for Series.resample() and DataFrame.resample(); - # see GH #37603 - with tm.assert_produces_warning(FutureWarning): - df.groupby("a").resample("3T", base=0).sum() - with tm.assert_produces_warning(FutureWarning): - df.groupby("a").resample("3T", loffset="0s").sum() - msg = "'offset' and 'base' cannot be present at the same time" - with tm.assert_produces_warning(FutureWarning): - with pytest.raises(ValueError, match=msg): - df.groupby("a").resample("3T", base=0, offset=0).sum() - - with tm.assert_produces_warning(FutureWarning): - df.resample("3T", base=0).sum() - with tm.assert_produces_warning(FutureWarning): - df.resample("3T", loffset="0s").sum() - - -@all_ts -@pytest.mark.parametrize("arg", ["mean", {"value": "mean"}, ["mean"]]) -def test_resample_loffset_arg_type(frame, create_index, arg): - # GH 13218, 15002 - df = frame - expected_means = [df.values[i : i + 2].mean() for i in range(0, len(df.values), 2)] - expected_index = create_index(df.index[0], periods=len(df.index) / 2, freq="2D") - - # loffset coerces PeriodIndex to DateTimeIndex - if isinstance(expected_index, PeriodIndex): - expected_index = expected_index.to_timestamp() - - expected_index += timedelta(hours=2) - expected = DataFrame({"value": expected_means}, index=expected_index) - - with tm.assert_produces_warning(FutureWarning): - result_agg = df.resample("2D", loffset="2H").agg(arg) - - if isinstance(arg, list): - expected.columns = pd.MultiIndex.from_tuples([("value", "mean")]) - - tm.assert_frame_equal(result_agg, expected) - - -@pytest.mark.parametrize( - "loffset", [timedelta(minutes=1), "1min", Minute(1), np.timedelta64(1, "m")] -) -def test_resample_loffset(loffset): - # GH 7687 - rng = date_range("1/1/2000 00:00:00", "1/1/2000 00:13:00", freq="min") - s = Series(np.random.randn(14), index=rng) - - with tm.assert_produces_warning(FutureWarning): - result = s.resample( - "5min", closed="right", label="right", loffset=loffset - ).mean() - idx = date_range("1/1/2000", periods=4, freq="5min") - expected = Series( - [s[0], s[1:6].mean(), s[6:11].mean(), s[11:].mean()], - index=idx + timedelta(minutes=1), - ) - tm.assert_series_equal(result, expected) - assert result.index.freq == Minute(5) - - # from daily - dti = date_range(start=datetime(2005, 1, 1), end=datetime(2005, 1, 10), freq="D") - ser = Series(np.random.rand(len(dti)), dti) - - # to weekly - result = ser.resample("w-sun").last() - business_day_offset = BDay() - with tm.assert_produces_warning(FutureWarning): - expected = ser.resample("w-sun", loffset=-business_day_offset).last() - assert result.index[0] - business_day_offset == expected.index[0] - - -def test_resample_loffset_upsample(): - # GH 20744 - rng = date_range("1/1/2000 00:00:00", "1/1/2000 00:13:00", freq="min") - s = Series(np.random.randn(14), index=rng) - - with tm.assert_produces_warning(FutureWarning): - result = s.resample( - "5min", closed="right", label="right", loffset=timedelta(minutes=1) - ).ffill() - idx = date_range("1/1/2000", periods=4, freq="5min") - expected = Series([s[0], s[5], s[10], s[-1]], index=idx + timedelta(minutes=1)) - - tm.assert_series_equal(result, expected) - - -def test_resample_loffset_count(): - # GH 12725 - start_time = "1/1/2000 00:00:00" - rng = date_range(start_time, periods=100, freq="S") - ts = Series(np.random.randn(len(rng)), index=rng) - - with tm.assert_produces_warning(FutureWarning): - result = ts.resample("10S", loffset="1s").count() - - expected_index = date_range(start_time, periods=10, freq="10S") + timedelta( - seconds=1 - ) - expected = Series(10, index=expected_index) - - tm.assert_series_equal(result, expected) - - # Same issue should apply to .size() since it goes through - # same code path - with tm.assert_produces_warning(FutureWarning): - result = ts.resample("10S", loffset="1s").size() - - tm.assert_series_equal(result, expected) - - -def test_resample_base(): - rng = date_range("1/1/2000 00:00:00", "1/1/2000 02:00", freq="s") - ts = Series(np.random.randn(len(rng)), index=rng) - - with tm.assert_produces_warning(FutureWarning): - resampled = ts.resample("5min", base=2).mean() - exp_rng = date_range("12/31/1999 23:57:00", "1/1/2000 01:57", freq="5min") - tm.assert_index_equal(resampled.index, exp_rng) - - -def test_resample_float_base(): - # GH25161 - dt = pd.to_datetime( - ["2018-11-26 16:17:43.51", "2018-11-26 16:17:44.51", "2018-11-26 16:17:45.51"] - ) - s = Series(np.arange(3), index=dt) - - base = 17 + 43.51 / 60 - with tm.assert_produces_warning(FutureWarning): - result = s.resample("3min", base=base).size() - expected = Series( - 3, index=pd.DatetimeIndex(["2018-11-26 16:17:43.51"], freq="3min") - ) - tm.assert_series_equal(result, expected) - - -@pytest.mark.parametrize("kind", ["period", None, "timestamp"]) -@pytest.mark.parametrize("agg_arg", ["mean", {"value": "mean"}, ["mean"]]) -def test_loffset_returns_datetimeindex(frame, kind, agg_arg): - # make sure passing loffset returns DatetimeIndex in all cases - # basic method taken from Base.test_resample_loffset_arg_type() - df = frame - expected_means = [df.values[i : i + 2].mean() for i in range(0, len(df.values), 2)] - expected_index = period_range(df.index[0], periods=len(df.index) / 2, freq="2D") - - # loffset coerces PeriodIndex to DateTimeIndex - expected_index = expected_index.to_timestamp() - expected_index += timedelta(hours=2) - expected = DataFrame({"value": expected_means}, index=expected_index) - - with tm.assert_produces_warning(FutureWarning): - result_agg = df.resample("2D", loffset="2H", kind=kind).agg(agg_arg) - if isinstance(agg_arg, list): - expected.columns = pd.MultiIndex.from_tuples([("value", "mean")]) - tm.assert_frame_equal(result_agg, expected) - - -@pytest.mark.parametrize( - "start,end,start_freq,end_freq,base,offset", - [ - ("19910905", "19910909 03:00", "H", "24H", 10, "10H"), - ("19910905", "19910909 12:00", "H", "24H", 10, "10H"), - ("19910905", "19910909 23:00", "H", "24H", 10, "10H"), - ("19910905 10:00", "19910909", "H", "24H", 10, "10H"), - ("19910905 10:00", "19910909 10:00", "H", "24H", 10, "10H"), - ("19910905", "19910909 10:00", "H", "24H", 10, "10H"), - ("19910905 12:00", "19910909", "H", "24H", 10, "10H"), - ("19910905 12:00", "19910909 03:00", "H", "24H", 10, "10H"), - ("19910905 12:00", "19910909 12:00", "H", "24H", 10, "10H"), - ("19910905 12:00", "19910909 12:00", "H", "24H", 34, "34H"), - ("19910905 12:00", "19910909 12:00", "H", "17H", 10, "10H"), - ("19910905 12:00", "19910909 12:00", "H", "17H", 3, "3H"), - ("19910905 12:00", "19910909 1:00", "H", "M", 3, "3H"), - ("19910905", "19910913 06:00", "2H", "24H", 10, "10H"), - ("19910905", "19910905 01:39", "Min", "5Min", 3, "3Min"), - ("19910905", "19910905 03:18", "2Min", "5Min", 3, "3Min"), - ], -) -def test_resample_with_non_zero_base(start, end, start_freq, end_freq, base, offset): - # GH 23882 - s = Series(0, index=period_range(start, end, freq=start_freq)) - s = s + np.arange(len(s)) - with tm.assert_produces_warning(FutureWarning): - result = s.resample(end_freq, base=base).mean() - result = result.to_timestamp(end_freq) - - # test that the replacement argument 'offset' works - result_offset = s.resample(end_freq, offset=offset).mean() - result_offset = result_offset.to_timestamp(end_freq) - tm.assert_series_equal(result, result_offset) - - # to_timestamp casts 24H -> D - result = result.asfreq(end_freq) if end_freq == "24H" else result - with tm.assert_produces_warning(FutureWarning): - expected = s.to_timestamp().resample(end_freq, base=base).mean() - if end_freq == "M": - # TODO: is non-tick the relevant characteristic? (GH 33815) - expected.index = expected.index._with_freq(None) - tm.assert_series_equal(result, expected) - - -def test_resample_base_with_timedeltaindex(): - # GH 10530 - rng = timedelta_range(start="0s", periods=25, freq="s") - ts = Series(np.random.randn(len(rng)), index=rng) - - with tm.assert_produces_warning(FutureWarning): - with_base = ts.resample("2s", base=5).mean() - without_base = ts.resample("2s").mean() - - exp_without_base = timedelta_range(start="0s", end="25s", freq="2s") - exp_with_base = timedelta_range(start="5s", end="29s", freq="2s") - - tm.assert_index_equal(without_base.index, exp_without_base) - tm.assert_index_equal(with_base.index, exp_with_base) def test_interpolate_posargs_deprecation(): From 79e0ccc91708013c6940b3386cdb3e429b9b1e5c Mon Sep 17 00:00:00 2001 From: Vamsi Verma Date: Wed, 19 Oct 2022 20:34:22 +0000 Subject: [PATCH 3/7] fix docstring for resample --- pandas/core/generic.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 5bd79a20c1e43..4f6c6434027fb 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -8856,7 +8856,6 @@ def resample( 2000-10-02 00:12:00 45 2000-10-02 00:29:00 45 Freq: 17T, dtype: int64 - """ from pandas.core.resample import get_resampler From af84f456746089737188dc61cefc92d86ac33f03 Mon Sep 17 00:00:00 2001 From: Vamsi Verma Date: Thu, 20 Oct 2022 13:15:12 +0000 Subject: [PATCH 4/7] change date_range import to avoid flake8 warning --- pandas/tests/resample/test_deprecated.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pandas/tests/resample/test_deprecated.py b/pandas/tests/resample/test_deprecated.py index 6002a128082e9..0cc9878ab721b 100644 --- a/pandas/tests/resample/test_deprecated.py +++ b/pandas/tests/resample/test_deprecated.py @@ -1,7 +1,9 @@ import pandas as pd -from pandas import Series +from pandas import ( + Series, + date_range, +) import pandas._testing as tm -from pandas.core.indexes.datetimes import date_range def test_interpolate_posargs_deprecation(): From c03c6ada52e99637d309497ab8093e4295ffbe40 Mon Sep 17 00:00:00 2001 From: Vamsi Verma Date: Thu, 20 Oct 2022 16:31:54 +0000 Subject: [PATCH 5/7] fix resample test_depecerated imports --- pandas/tests/resample/test_deprecated.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pandas/tests/resample/test_deprecated.py b/pandas/tests/resample/test_deprecated.py index aa0de7a9a3de7..4c37eac79ef1f 100644 --- a/pandas/tests/resample/test_deprecated.py +++ b/pandas/tests/resample/test_deprecated.py @@ -1,8 +1,5 @@ import pandas as pd -from pandas import ( - Series, - date_range, -) +from pandas import Series import pandas._testing as tm From e16dc0836d97de8c7451dd4a4623368f4d3d8a6d Mon Sep 17 00:00:00 2001 From: Vamsi Verma Date: Fri, 28 Oct 2022 01:13:38 +0000 Subject: [PATCH 6/7] move change note to deprecation section --- doc/source/whatsnew/v2.0.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 31ee24d2caf23..1b47e4aaac0d4 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -257,6 +257,7 @@ Removal of prior version deprecations/changes - Changed behavior of :class:`DataFrame` constructor when passed a ``dtype`` (other than int) that the data cannot be cast to; it now raises instead of silently ignoring the dtype (:issue:`41733`) - Changed the behavior of :class:`Series` constructor, it will no longer infer a datetime64 or timedelta64 dtype from string entries (:issue:`41731`) - Changed behavior of :class:`Index` constructor when passed a ``SparseArray`` or ``SparseDtype`` to retain that dtype instead of casting to ``numpy.ndarray`` (:issue:`43930`) +- Removed the deprecated ``base`` and ``loffset`` arguments from :meth:`pandas.DataFrame.resample`, :meth:`pandas.Series.resample` and :class:`pandas.Grouper`. Use ``offset`` or ``origin`` instead (:issue:`31809`) .. --------------------------------------------------------------------------- .. _whatsnew_200.performance: @@ -396,7 +397,6 @@ Groupby/resample/rolling - Bug in :meth:`DataFrameGroupBy.sample` raises ``ValueError`` when the object is empty (:issue:`48459`) - Bug in :meth:`Series.groupby` raises ``ValueError`` when an entry of the index is equal to the name of the index (:issue:`48567`) - Bug in :meth:`DataFrameGroupBy.resample` produces inconsistent results when passing empty DataFrame (:issue:`47705`) -- Removed the previously deprecated ``base`` and ``loffset`` arguments from :meth:`pandas.DataFrame.resample`, :meth:`pandas.Series.resample` and :class:`pandas.Grouper`. Use ``offset`` or ``origin`` instead (:issue:`31809`) - Reshaping From e38b8039e9a4648c7597bfa6cb048bc21a263d06 Mon Sep 17 00:00:00 2001 From: Vamsi Verma Date: Sun, 30 Oct 2022 02:50:51 +0000 Subject: [PATCH 7/7] remove all deprecated tests for resample --- pandas/tests/resample/test_deprecated.py | 30 ------------------------ 1 file changed, 30 deletions(-) delete mode 100644 pandas/tests/resample/test_deprecated.py diff --git a/pandas/tests/resample/test_deprecated.py b/pandas/tests/resample/test_deprecated.py deleted file mode 100644 index 4c37eac79ef1f..0000000000000 --- a/pandas/tests/resample/test_deprecated.py +++ /dev/null @@ -1,30 +0,0 @@ -import pandas as pd -from pandas import Series -import pandas._testing as tm - - -def test_interpolate_posargs_deprecation(): - # GH 41485 - idx = pd.to_datetime(["1992-08-27 07:46:48", "1992-08-27 07:46:59"]) - s = Series([1, 4], index=idx) - - msg = ( - r"In a future version of pandas all arguments of Resampler\.interpolate " - r"except for the argument 'method' will be keyword-only" - ) - - with tm.assert_produces_warning(FutureWarning, match=msg): - result = s.resample("3s").interpolate("linear", 0) - - idx = pd.to_datetime( - [ - "1992-08-27 07:46:48", - "1992-08-27 07:46:51", - "1992-08-27 07:46:54", - "1992-08-27 07:46:57", - ] - ) - expected = Series([1.0, 1.0, 1.0, 1.0], index=idx) - - expected.index._data.freq = "3s" - tm.assert_series_equal(result, expected)