From 1d0ca0fa0da1127debb33d3d135b4340dbd0af0e Mon Sep 17 00:00:00 2001 From: Brock Date: Wed, 21 Sep 2022 09:44:48 -0700 Subject: [PATCH 1/4] DEPR: enforce deprecations on DateOffset methods --- doc/source/reference/offset_frequency.rst | 175 ------------------ doc/source/whatsnew/v1.6.0.rst | 2 +- pandas/_libs/tslibs/offsets.pyx | 67 ------- .../tseries/offsets/test_business_day.py | 8 +- .../tseries/offsets/test_business_hour.py | 18 +- .../offsets/test_custom_business_hour.py | 9 +- .../offsets/test_custom_business_month.py | 12 +- pandas/tests/tseries/offsets/test_month.py | 4 - pandas/tests/tseries/offsets/test_offsets.py | 31 ---- 9 files changed, 19 insertions(+), 307 deletions(-) diff --git a/doc/source/reference/offset_frequency.rst b/doc/source/reference/offset_frequency.rst index f0e531cd81f84..ab89fe74e7337 100644 --- a/doc/source/reference/offset_frequency.rst +++ b/doc/source/reference/offset_frequency.rst @@ -34,14 +34,9 @@ Methods .. autosummary:: :toctree: api/ - DateOffset.apply - DateOffset.apply_index DateOffset.copy - DateOffset.isAnchored - DateOffset.onOffset DateOffset.is_anchored DateOffset.is_on_offset - DateOffset.__call__ DateOffset.is_month_start DateOffset.is_month_end DateOffset.is_quarter_start @@ -86,14 +81,9 @@ Methods .. autosummary:: :toctree: api/ - BusinessDay.apply - BusinessDay.apply_index BusinessDay.copy - BusinessDay.isAnchored - BusinessDay.onOffset BusinessDay.is_anchored BusinessDay.is_on_offset - BusinessDay.__call__ BusinessDay.is_month_start BusinessDay.is_month_end BusinessDay.is_quarter_start @@ -131,14 +121,9 @@ Methods .. autosummary:: :toctree: api/ - BusinessHour.apply - BusinessHour.apply_index BusinessHour.copy - BusinessHour.isAnchored - BusinessHour.onOffset BusinessHour.is_anchored BusinessHour.is_on_offset - BusinessHour.__call__ BusinessHour.is_month_start BusinessHour.is_month_end BusinessHour.is_quarter_start @@ -183,14 +168,9 @@ Methods .. autosummary:: :toctree: api/ - CustomBusinessDay.apply_index - CustomBusinessDay.apply CustomBusinessDay.copy - CustomBusinessDay.isAnchored - CustomBusinessDay.onOffset CustomBusinessDay.is_anchored CustomBusinessDay.is_on_offset - CustomBusinessDay.__call__ CustomBusinessDay.is_month_start CustomBusinessDay.is_month_end CustomBusinessDay.is_quarter_start @@ -228,14 +208,9 @@ Methods .. autosummary:: :toctree: api/ - CustomBusinessHour.apply - CustomBusinessHour.apply_index CustomBusinessHour.copy - CustomBusinessHour.isAnchored - CustomBusinessHour.onOffset CustomBusinessHour.is_anchored CustomBusinessHour.is_on_offset - CustomBusinessHour.__call__ CustomBusinessHour.is_month_start CustomBusinessHour.is_month_end CustomBusinessHour.is_quarter_start @@ -268,14 +243,9 @@ Methods .. autosummary:: :toctree: api/ - MonthEnd.apply - MonthEnd.apply_index MonthEnd.copy - MonthEnd.isAnchored - MonthEnd.onOffset MonthEnd.is_anchored MonthEnd.is_on_offset - MonthEnd.__call__ MonthEnd.is_month_start MonthEnd.is_month_end MonthEnd.is_quarter_start @@ -308,14 +278,9 @@ Methods .. autosummary:: :toctree: api/ - MonthBegin.apply - MonthBegin.apply_index MonthBegin.copy - MonthBegin.isAnchored - MonthBegin.onOffset MonthBegin.is_anchored MonthBegin.is_on_offset - MonthBegin.__call__ MonthBegin.is_month_start MonthBegin.is_month_end MonthBegin.is_quarter_start @@ -357,14 +322,9 @@ Methods .. autosummary:: :toctree: api/ - BusinessMonthEnd.apply - BusinessMonthEnd.apply_index BusinessMonthEnd.copy - BusinessMonthEnd.isAnchored - BusinessMonthEnd.onOffset BusinessMonthEnd.is_anchored BusinessMonthEnd.is_on_offset - BusinessMonthEnd.__call__ BusinessMonthEnd.is_month_start BusinessMonthEnd.is_month_end BusinessMonthEnd.is_quarter_start @@ -406,14 +366,9 @@ Methods .. autosummary:: :toctree: api/ - BusinessMonthBegin.apply - BusinessMonthBegin.apply_index BusinessMonthBegin.copy - BusinessMonthBegin.isAnchored - BusinessMonthBegin.onOffset BusinessMonthBegin.is_anchored BusinessMonthBegin.is_on_offset - BusinessMonthBegin.__call__ BusinessMonthBegin.is_month_start BusinessMonthBegin.is_month_end BusinessMonthBegin.is_quarter_start @@ -459,14 +414,9 @@ Methods .. autosummary:: :toctree: api/ - CustomBusinessMonthEnd.apply - CustomBusinessMonthEnd.apply_index CustomBusinessMonthEnd.copy - CustomBusinessMonthEnd.isAnchored - CustomBusinessMonthEnd.onOffset CustomBusinessMonthEnd.is_anchored CustomBusinessMonthEnd.is_on_offset - CustomBusinessMonthEnd.__call__ CustomBusinessMonthEnd.is_month_start CustomBusinessMonthEnd.is_month_end CustomBusinessMonthEnd.is_quarter_start @@ -512,14 +462,9 @@ Methods .. autosummary:: :toctree: api/ - CustomBusinessMonthBegin.apply - CustomBusinessMonthBegin.apply_index CustomBusinessMonthBegin.copy - CustomBusinessMonthBegin.isAnchored - CustomBusinessMonthBegin.onOffset CustomBusinessMonthBegin.is_anchored CustomBusinessMonthBegin.is_on_offset - CustomBusinessMonthBegin.__call__ CustomBusinessMonthBegin.is_month_start CustomBusinessMonthBegin.is_month_end CustomBusinessMonthBegin.is_quarter_start @@ -553,14 +498,9 @@ Methods .. autosummary:: :toctree: api/ - SemiMonthEnd.apply - SemiMonthEnd.apply_index SemiMonthEnd.copy - SemiMonthEnd.isAnchored - SemiMonthEnd.onOffset SemiMonthEnd.is_anchored SemiMonthEnd.is_on_offset - SemiMonthEnd.__call__ SemiMonthEnd.is_month_start SemiMonthEnd.is_month_end SemiMonthEnd.is_quarter_start @@ -594,14 +534,9 @@ Methods .. autosummary:: :toctree: api/ - SemiMonthBegin.apply - SemiMonthBegin.apply_index SemiMonthBegin.copy - SemiMonthBegin.isAnchored - SemiMonthBegin.onOffset SemiMonthBegin.is_anchored SemiMonthBegin.is_on_offset - SemiMonthBegin.__call__ SemiMonthBegin.is_month_start SemiMonthBegin.is_month_end SemiMonthBegin.is_quarter_start @@ -635,14 +570,9 @@ Methods .. autosummary:: :toctree: api/ - Week.apply - Week.apply_index Week.copy - Week.isAnchored - Week.onOffset Week.is_anchored Week.is_on_offset - Week.__call__ Week.is_month_start Week.is_month_end Week.is_quarter_start @@ -676,14 +606,9 @@ Methods .. autosummary:: :toctree: api/ - WeekOfMonth.apply - WeekOfMonth.apply_index WeekOfMonth.copy - WeekOfMonth.isAnchored - WeekOfMonth.onOffset WeekOfMonth.is_anchored WeekOfMonth.is_on_offset - WeekOfMonth.__call__ WeekOfMonth.weekday WeekOfMonth.is_month_start WeekOfMonth.is_month_end @@ -719,14 +644,9 @@ Methods .. autosummary:: :toctree: api/ - LastWeekOfMonth.apply - LastWeekOfMonth.apply_index LastWeekOfMonth.copy - LastWeekOfMonth.isAnchored - LastWeekOfMonth.onOffset LastWeekOfMonth.is_anchored LastWeekOfMonth.is_on_offset - LastWeekOfMonth.__call__ LastWeekOfMonth.is_month_start LastWeekOfMonth.is_month_end LastWeekOfMonth.is_quarter_start @@ -760,14 +680,9 @@ Methods .. autosummary:: :toctree: api/ - BQuarterEnd.apply - BQuarterEnd.apply_index BQuarterEnd.copy - BQuarterEnd.isAnchored - BQuarterEnd.onOffset BQuarterEnd.is_anchored BQuarterEnd.is_on_offset - BQuarterEnd.__call__ BQuarterEnd.is_month_start BQuarterEnd.is_month_end BQuarterEnd.is_quarter_start @@ -801,14 +716,9 @@ Methods .. autosummary:: :toctree: api/ - BQuarterBegin.apply - BQuarterBegin.apply_index BQuarterBegin.copy - BQuarterBegin.isAnchored - BQuarterBegin.onOffset BQuarterBegin.is_anchored BQuarterBegin.is_on_offset - BQuarterBegin.__call__ BQuarterBegin.is_month_start BQuarterBegin.is_month_end BQuarterBegin.is_quarter_start @@ -842,14 +752,9 @@ Methods .. autosummary:: :toctree: api/ - QuarterEnd.apply - QuarterEnd.apply_index QuarterEnd.copy - QuarterEnd.isAnchored - QuarterEnd.onOffset QuarterEnd.is_anchored QuarterEnd.is_on_offset - QuarterEnd.__call__ QuarterEnd.is_month_start QuarterEnd.is_month_end QuarterEnd.is_quarter_start @@ -883,14 +788,9 @@ Methods .. autosummary:: :toctree: api/ - QuarterBegin.apply - QuarterBegin.apply_index QuarterBegin.copy - QuarterBegin.isAnchored - QuarterBegin.onOffset QuarterBegin.is_anchored QuarterBegin.is_on_offset - QuarterBegin.__call__ QuarterBegin.is_month_start QuarterBegin.is_month_end QuarterBegin.is_quarter_start @@ -924,14 +824,9 @@ Methods .. autosummary:: :toctree: api/ - BYearEnd.apply - BYearEnd.apply_index BYearEnd.copy - BYearEnd.isAnchored - BYearEnd.onOffset BYearEnd.is_anchored BYearEnd.is_on_offset - BYearEnd.__call__ BYearEnd.is_month_start BYearEnd.is_month_end BYearEnd.is_quarter_start @@ -965,14 +860,9 @@ Methods .. autosummary:: :toctree: api/ - BYearBegin.apply - BYearBegin.apply_index BYearBegin.copy - BYearBegin.isAnchored - BYearBegin.onOffset BYearBegin.is_anchored BYearBegin.is_on_offset - BYearBegin.__call__ BYearBegin.is_month_start BYearBegin.is_month_end BYearBegin.is_quarter_start @@ -1006,14 +896,9 @@ Methods .. autosummary:: :toctree: api/ - YearEnd.apply - YearEnd.apply_index YearEnd.copy - YearEnd.isAnchored - YearEnd.onOffset YearEnd.is_anchored YearEnd.is_on_offset - YearEnd.__call__ YearEnd.is_month_start YearEnd.is_month_end YearEnd.is_quarter_start @@ -1047,14 +932,9 @@ Methods .. autosummary:: :toctree: api/ - YearBegin.apply - YearBegin.apply_index YearBegin.copy - YearBegin.isAnchored - YearBegin.onOffset YearBegin.is_anchored YearBegin.is_on_offset - YearBegin.__call__ YearBegin.is_month_start YearBegin.is_month_end YearBegin.is_quarter_start @@ -1090,16 +970,11 @@ Methods .. autosummary:: :toctree: api/ - FY5253.apply - FY5253.apply_index FY5253.copy FY5253.get_rule_code_suffix FY5253.get_year_end - FY5253.isAnchored - FY5253.onOffset FY5253.is_anchored FY5253.is_on_offset - FY5253.__call__ FY5253.is_month_start FY5253.is_month_end FY5253.is_quarter_start @@ -1136,17 +1011,12 @@ Methods .. autosummary:: :toctree: api/ - FY5253Quarter.apply - FY5253Quarter.apply_index FY5253Quarter.copy FY5253Quarter.get_rule_code_suffix FY5253Quarter.get_weeks - FY5253Quarter.isAnchored - FY5253Quarter.onOffset FY5253Quarter.is_anchored FY5253Quarter.is_on_offset FY5253Quarter.year_has_extra_week - FY5253Quarter.__call__ FY5253Quarter.is_month_start FY5253Quarter.is_month_end FY5253Quarter.is_quarter_start @@ -1179,14 +1049,9 @@ Methods .. autosummary:: :toctree: api/ - Easter.apply - Easter.apply_index Easter.copy - Easter.isAnchored - Easter.onOffset Easter.is_anchored Easter.is_on_offset - Easter.__call__ Easter.is_month_start Easter.is_month_end Easter.is_quarter_start @@ -1221,13 +1086,8 @@ Methods :toctree: api/ Tick.copy - Tick.isAnchored - Tick.onOffset Tick.is_anchored Tick.is_on_offset - Tick.__call__ - Tick.apply - Tick.apply_index Tick.is_month_start Tick.is_month_end Tick.is_quarter_start @@ -1262,13 +1122,8 @@ Methods :toctree: api/ Day.copy - Day.isAnchored - Day.onOffset Day.is_anchored Day.is_on_offset - Day.__call__ - Day.apply - Day.apply_index Day.is_month_start Day.is_month_end Day.is_quarter_start @@ -1303,13 +1158,8 @@ Methods :toctree: api/ Hour.copy - Hour.isAnchored - Hour.onOffset Hour.is_anchored Hour.is_on_offset - Hour.__call__ - Hour.apply - Hour.apply_index Hour.is_month_start Hour.is_month_end Hour.is_quarter_start @@ -1344,13 +1194,8 @@ Methods :toctree: api/ Minute.copy - Minute.isAnchored - Minute.onOffset Minute.is_anchored Minute.is_on_offset - Minute.__call__ - Minute.apply - Minute.apply_index Minute.is_month_start Minute.is_month_end Minute.is_quarter_start @@ -1385,13 +1230,8 @@ Methods :toctree: api/ Second.copy - Second.isAnchored - Second.onOffset Second.is_anchored Second.is_on_offset - Second.__call__ - Second.apply - Second.apply_index Second.is_month_start Second.is_month_end Second.is_quarter_start @@ -1426,13 +1266,8 @@ Methods :toctree: api/ Milli.copy - Milli.isAnchored - Milli.onOffset Milli.is_anchored Milli.is_on_offset - Milli.__call__ - Milli.apply - Milli.apply_index Milli.is_month_start Milli.is_month_end Milli.is_quarter_start @@ -1467,13 +1302,8 @@ Methods :toctree: api/ Micro.copy - Micro.isAnchored - Micro.onOffset Micro.is_anchored Micro.is_on_offset - Micro.__call__ - Micro.apply - Micro.apply_index Micro.is_month_start Micro.is_month_end Micro.is_quarter_start @@ -1508,13 +1338,8 @@ Methods :toctree: api/ Nano.copy - Nano.isAnchored - Nano.onOffset Nano.is_anchored Nano.is_on_offset - Nano.__call__ - Nano.apply - Nano.apply_index Nano.is_month_start Nano.is_month_end Nano.is_quarter_start diff --git a/doc/source/whatsnew/v1.6.0.rst b/doc/source/whatsnew/v1.6.0.rst index d726f69286469..5adefd6f475ed 100644 --- a/doc/source/whatsnew/v1.6.0.rst +++ b/doc/source/whatsnew/v1.6.0.rst @@ -123,7 +123,7 @@ Other API changes Deprecations ~~~~~~~~~~~~ -- +- Removed deprecated ``apply``, ``apply_index``, ``__call__``, ``onOffset``, and ``isAnchored`` attributes from :class:`DateOffset` (:issue:`34171`) - .. --------------------------------------------------------------------------- diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 7be7381bcb4d1..fe3fc4b4d3da3 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -1,9 +1,5 @@ -import inspect import re import time -import warnings - -from pandas.util._exceptions import find_stack_level cimport cython from cpython.datetime cimport ( @@ -496,25 +492,6 @@ cdef class BaseOffset: def __rsub__(self, other): return (-self).__add__(other) - def __call__(self, other): - warnings.warn( - "DateOffset.__call__ is deprecated and will be removed in a future " - "version. Use `offset + other` instead.", - FutureWarning, - stacklevel=find_stack_level(inspect.currentframe()), - ) - return self._apply(other) - - def apply(self, other): - # GH#44522 - warnings.warn( - f"{type(self).__name__}.apply is deprecated and will be removed " - "in a future version. Use `offset + other` instead", - FutureWarning, - stacklevel=find_stack_level(inspect.currentframe()), - ) - return self._apply(other) - def __mul__(self, other): if util.is_array(other): return np.array([self * x for x in other]) @@ -653,34 +630,6 @@ cdef class BaseOffset: # ------------------------------------------------------------------ - def apply_index(self, dtindex): - """ - Vectorized apply of DateOffset to DatetimeIndex. - - .. deprecated:: 1.1.0 - - Use ``offset + dtindex`` instead. - - Parameters - ---------- - index : DatetimeIndex - - Returns - ------- - DatetimeIndex - - Raises - ------ - NotImplementedError - When the specific offset subclass does not have a vectorized - implementation. - """ - warnings.warn("'Offset.apply_index(other)' is deprecated. " - "Use 'offset + other' instead.", FutureWarning) - - res = self._apply_array(dtindex) - return type(dtindex)(res) - def _apply(self, other): raise NotImplementedError("implemented by subclasses") @@ -821,22 +770,6 @@ cdef class BaseOffset: def nanos(self): raise ValueError(f"{self} is a non-fixed frequency") - def onOffset(self, dt) -> bool: - warnings.warn( - "onOffset is a deprecated, use is_on_offset instead.", - FutureWarning, - stacklevel=find_stack_level(inspect.currentframe()), - ) - return self.is_on_offset(dt) - - def isAnchored(self) -> bool: - warnings.warn( - "isAnchored is a deprecated, use is_anchored instead.", - FutureWarning, - stacklevel=find_stack_level(inspect.currentframe()), - ) - return self.is_anchored() - def is_anchored(self) -> bool: # TODO: Does this make sense for the general case? It would help # if there were a canonical docstring for what is_anchored means. diff --git a/pandas/tests/tseries/offsets/test_business_day.py b/pandas/tests/tseries/offsets/test_business_day.py index f23772dd0bd7c..55bfc4ebe717d 100644 --- a/pandas/tests/tseries/offsets/test_business_day.py +++ b/pandas/tests/tseries/offsets/test_business_day.py @@ -90,11 +90,9 @@ def test_mul(self): def test_hash(self): assert hash(self.offset2) == hash(self.offset2) - def test_call(self): - with tm.assert_produces_warning(FutureWarning): - # GH#34171 DateOffset.__call__ is deprecated - assert self.offset2(self.d) == datetime(2008, 1, 3) - assert self.offset2(self.nd) == datetime(2008, 1, 3) + def test_add_datetime(self): + assert self.offset2 + self.d == datetime(2008, 1, 3) + assert self.offset2 + self.nd == datetime(2008, 1, 3) def testRollback1(self): assert self._offset(10).rollback(self.d) == self.d diff --git a/pandas/tests/tseries/offsets/test_business_hour.py b/pandas/tests/tseries/offsets/test_business_hour.py index 392991009a449..9b63511a6ffaa 100644 --- a/pandas/tests/tseries/offsets/test_business_hour.py +++ b/pandas/tests/tseries/offsets/test_business_hour.py @@ -168,16 +168,14 @@ def test_hash(self, offset_name): offset = getattr(self, offset_name) assert offset == offset - def test_call(self): - with tm.assert_produces_warning(FutureWarning): - # GH#34171 DateOffset.__call__ is deprecated - assert self.offset1(self.d) == datetime(2014, 7, 1, 11) - assert self.offset2(self.d) == datetime(2014, 7, 1, 13) - assert self.offset3(self.d) == datetime(2014, 6, 30, 17) - assert self.offset4(self.d) == datetime(2014, 6, 30, 14) - assert self.offset8(self.d) == datetime(2014, 7, 1, 11) - assert self.offset9(self.d) == datetime(2014, 7, 1, 22) - assert self.offset10(self.d) == datetime(2014, 7, 1, 1) + def test_add_datetime(self): + assert self.offset1 + self.d == datetime(2014, 7, 1, 11) + assert self.offset2 + self.d == datetime(2014, 7, 1, 13) + assert self.offset3 + self.d == datetime(2014, 6, 30, 17) + assert self.offset4 + self.d == datetime(2014, 6, 30, 14) + assert self.offset8 + self.d == datetime(2014, 7, 1, 11) + assert self.offset9 + self.d == datetime(2014, 7, 1, 22) + assert self.offset10 + self.d == datetime(2014, 7, 1, 1) def test_sub(self): # we have to override test_sub here because self.offset2 is not diff --git a/pandas/tests/tseries/offsets/test_custom_business_hour.py b/pandas/tests/tseries/offsets/test_custom_business_hour.py index 9a2d24f1d0307..086fcbf329bdd 100644 --- a/pandas/tests/tseries/offsets/test_custom_business_hour.py +++ b/pandas/tests/tseries/offsets/test_custom_business_hour.py @@ -15,7 +15,6 @@ Nano, ) -import pandas._testing as tm from pandas.tests.tseries.offsets.common import ( Base, assert_offset_equal, @@ -95,11 +94,9 @@ def test_hash(self): assert hash(self.offset1) == hash(self.offset1) assert hash(self.offset2) == hash(self.offset2) - def test_call(self): - with tm.assert_produces_warning(FutureWarning): - # GH#34171 DateOffset.__call__ is deprecated - assert self.offset1(self.d) == datetime(2014, 7, 1, 11) - assert self.offset2(self.d) == datetime(2014, 7, 1, 11) + def test_add_dateime(self): + assert self.offset1 + self.d == datetime(2014, 7, 1, 11) + assert self.offset2 + self.d == datetime(2014, 7, 1, 11) def testRollback1(self): assert self.offset1.rollback(self.d) == self.d diff --git a/pandas/tests/tseries/offsets/test_custom_business_month.py b/pandas/tests/tseries/offsets/test_custom_business_month.py index c0f9b3cb5be87..333c14c1a6c60 100644 --- a/pandas/tests/tseries/offsets/test_custom_business_month.py +++ b/pandas/tests/tseries/offsets/test_custom_business_month.py @@ -81,10 +81,8 @@ def test_repr(self): assert repr(self.offset) == "" assert repr(self.offset2) == "<2 * CustomBusinessMonthBegins>" - def test_call(self): - with tm.assert_produces_warning(FutureWarning): - # GH#34171 DateOffset.__call__ is deprecated - assert self.offset2(self.d) == datetime(2008, 3, 3) + def test_add_datetime(self): + assert self.offset2 + self.d == datetime(2008, 3, 3) def testRollback1(self): assert CDay(10).rollback(datetime(2007, 12, 31)) == datetime(2007, 12, 31) @@ -271,10 +269,8 @@ def test_repr(self): assert repr(self.offset) == "" assert repr(self.offset2) == "<2 * CustomBusinessMonthEnds>" - def test_call(self): - with tm.assert_produces_warning(FutureWarning): - # GH#34171 DateOffset.__call__ is deprecated - assert self.offset2(self.d) == datetime(2008, 2, 29) + def test_add_datetime(self): + assert self.offset2 + self.d == datetime(2008, 2, 29) def testRollback1(self): assert CDay(10).rollback(datetime(2007, 12, 31)) == datetime(2007, 12, 31) diff --git a/pandas/tests/tseries/offsets/test_month.py b/pandas/tests/tseries/offsets/test_month.py index 305b57cea17b1..e645b6ae19793 100644 --- a/pandas/tests/tseries/offsets/test_month.py +++ b/pandas/tests/tseries/offsets/test_month.py @@ -230,10 +230,6 @@ def test_apply_index(self, case): result = offset + shift tm.assert_index_equal(result, exp) - with tm.assert_produces_warning(FutureWarning): - result = offset.apply_index(shift) - tm.assert_index_equal(result, exp) - on_offset_cases = [ (datetime(2007, 12, 31), True), (datetime(2007, 12, 15), True), diff --git a/pandas/tests/tseries/offsets/test_offsets.py b/pandas/tests/tseries/offsets/test_offsets.py index bca4ba98f37b7..ebbbbfb88c40b 100644 --- a/pandas/tests/tseries/offsets/test_offsets.py +++ b/pandas/tests/tseries/offsets/test_offsets.py @@ -213,16 +213,6 @@ def _check_offsetfunc_works(self, offset, funcname, dt, expected, normalize=Fals with tm.assert_produces_warning(exp_warning): result = func(ts) - if exp_warning is None and funcname == "_apply": - # GH#44522 - # Check in this particular case to avoid headaches with - # testing for multiple warnings produced by the same call. - with tm.assert_produces_warning(FutureWarning, match="apply is deprecated"): - res2 = offset_s.apply(ts) - - assert type(res2) is type(result) - assert res2 == result - assert isinstance(result, Timestamp) if normalize is False: assert result == expected + Nano(5) @@ -526,27 +516,6 @@ def test_pickle_dateoffset_odd_inputs(self): base_dt = datetime(2020, 1, 1) assert base_dt + off == base_dt + res - def test_onOffset_deprecated(self, offset_types, fixed_now_ts): - # GH#30340 use idiomatic naming - off = self._get_offset(offset_types) - - ts = fixed_now_ts - with tm.assert_produces_warning(FutureWarning): - result = off.onOffset(ts) - - expected = off.is_on_offset(ts) - assert result == expected - - def test_isAnchored_deprecated(self, offset_types): - # GH#30340 use idiomatic naming - off = self._get_offset(offset_types) - - with tm.assert_produces_warning(FutureWarning): - result = off.isAnchored() - - expected = off.is_anchored() - assert result == expected - def test_offsets_hashable(self, offset_types): # GH: 37267 off = self._get_offset(offset_types) From 6a8bedfcb12c7ffdeca7c218f2a089bc1e0f2559 Mon Sep 17 00:00:00 2001 From: Brock Date: Wed, 21 Sep 2022 10:43:33 -0700 Subject: [PATCH 2/4] mypy fixup --- pandas/_libs/tslibs/offsets.pyi | 7 ------- 1 file changed, 7 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyi b/pandas/_libs/tslibs/offsets.pyi index 0390aad23d83a..0356065dec5fd 100644 --- a/pandas/_libs/tslibs/offsets.pyi +++ b/pandas/_libs/tslibs/offsets.pyi @@ -3,7 +3,6 @@ from datetime import ( timedelta, ) from typing import ( - TYPE_CHECKING, Any, Collection, Literal, @@ -17,8 +16,6 @@ from pandas._typing import npt from .timedeltas import Timedelta -if TYPE_CHECKING: - from pandas.core.indexes.datetimes import DatetimeIndex _BaseOffsetT = TypeVar("_BaseOffsetT", bound=BaseOffset) _DatetimeT = TypeVar("_DatetimeT", bound=datetime) _TimedeltaT = TypeVar("_TimedeltaT", bound=timedelta) @@ -63,7 +60,6 @@ class BaseOffset: def __rsub__(self, other: _DatetimeT) -> _DatetimeT: ... @overload def __rsub__(self, other: _TimedeltaT) -> _TimedeltaT: ... - def __call__(self, other): ... @overload def __mul__(self, other: np.ndarray) -> np.ndarray: ... @overload @@ -80,7 +76,6 @@ class BaseOffset: def rule_code(self) -> str: ... @property def freqstr(self) -> str: ... - def apply_index(self, dtindex: DatetimeIndex) -> DatetimeIndex: ... def _apply(self, other): ... def _apply_array(self, dtarr) -> None: ... def rollback(self, dt: datetime) -> datetime: ... @@ -90,8 +85,6 @@ class BaseOffset: def __getstate__(self): ... @property def nanos(self) -> int: ... - def onOffset(self, dt: datetime) -> bool: ... - def isAnchored(self) -> bool: ... def is_anchored(self) -> bool: ... def _get_offset(name: str) -> BaseOffset: ... From a5a4cf0e64855fa306ce5dc5cef68c90a3d1de64 Mon Sep 17 00:00:00 2001 From: Brock Date: Thu, 22 Sep 2022 07:53:06 -0700 Subject: [PATCH 3/4] fix asv --- asv_bench/benchmarks/tslibs/offsets.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/asv_bench/benchmarks/tslibs/offsets.py b/asv_bench/benchmarks/tslibs/offsets.py index 978a36e470cbb..a3fdaf8afdda1 100644 --- a/asv_bench/benchmarks/tslibs/offsets.py +++ b/asv_bench/benchmarks/tslibs/offsets.py @@ -71,11 +71,8 @@ def setup(self, offset): self.date = datetime(2011, 1, 1) self.dt64 = np.datetime64("2011-01-01 09:00Z") - def time_apply(self, offset): - offset.apply(self.date) - - def time_apply_np_dt64(self, offset): - offset.apply(self.dt64) + def time_add_np_dt64(self, offset): + offset + self.dt64 def time_add(self, offset): self.date + offset From 6f6e2ae6621a5aadf0dbafc05438f31b6a4bc713 Mon Sep 17 00:00:00 2001 From: Brock Date: Thu, 20 Oct 2022 10:03:09 -0700 Subject: [PATCH 4/4] move whatsnew --- 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 91a2e13611ef2..1202fa7b12ff8 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -136,7 +136,6 @@ Other API changes Deprecations ~~~~~~~~~~~~ -- Removed deprecated ``apply``, ``apply_index``, ``__call__``, ``onOffset``, and ``isAnchored`` attributes from :class:`DateOffset` (:issue:`34171`) - .. --------------------------------------------------------------------------- @@ -149,6 +148,7 @@ Removal of prior version deprecations/changes :func:`~pandas.io.date_converters.parse_date_fields`, :func:`~pandas.io.date_converters.parse_all_fields` and :func:`~pandas.io.date_converters.generic_parser` (:issue:`24518`) - Remove argument ``squeeze`` from :meth:`DataFrame.groupby` and :meth:`Series.groupby` (:issue:`32380`) +- Removed deprecated ``apply``, ``apply_index``, ``__call__``, ``onOffset``, and ``isAnchored`` attributes from :class:`DateOffset` (:issue:`34171`) - Removed ``keep_tz`` argument in :meth:`DatetimeIndex.to_series` (:issue:`29731`) - Remove arguments ``names`` and ``dtype`` from :meth:`Index.copy` and ``levels`` and ``codes`` from :meth:`MultiIndex.copy` (:issue:`35853`, :issue:`36685`) - Remove argument ``inplace`` from :meth:`MultiIndex.set_levels` and :meth:`MultiIndex.set_codes` (:issue:`35626`)