Skip to content

Commit 4f99269

Browse files
committed
DEPR: enforce deprecations on DateOffset methods
1 parent 73d15a7 commit 4f99269

File tree

9 files changed

+19
-307
lines changed

9 files changed

+19
-307
lines changed

doc/source/reference/offset_frequency.rst

Lines changed: 0 additions & 175 deletions
Large diffs are not rendered by default.

doc/source/whatsnew/v1.6.0.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ Other API changes
123123

124124
Deprecations
125125
~~~~~~~~~~~~
126-
-
126+
- Removed deprecated ``apply``, ``apply_index``, ``__call__``, ``onOffset``, and ``isAnchored`` attributes from :class:`DateOffset` (:issue:`34171`)
127127
-
128128

129129
.. ---------------------------------------------------------------------------

pandas/_libs/tslibs/offsets.pyx

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
import inspect
21
import re
32
import time
4-
import warnings
5-
6-
from pandas.util._exceptions import find_stack_level
73

84
cimport cython
95
from cpython.datetime cimport (
@@ -496,25 +492,6 @@ cdef class BaseOffset:
496492
def __rsub__(self, other):
497493
return (-self).__add__(other)
498494

499-
def __call__(self, other):
500-
warnings.warn(
501-
"DateOffset.__call__ is deprecated and will be removed in a future "
502-
"version. Use `offset + other` instead.",
503-
FutureWarning,
504-
stacklevel=find_stack_level(inspect.currentframe()),
505-
)
506-
return self._apply(other)
507-
508-
def apply(self, other):
509-
# GH#44522
510-
warnings.warn(
511-
f"{type(self).__name__}.apply is deprecated and will be removed "
512-
"in a future version. Use `offset + other` instead",
513-
FutureWarning,
514-
stacklevel=find_stack_level(inspect.currentframe()),
515-
)
516-
return self._apply(other)
517-
518495
def __mul__(self, other):
519496
if util.is_array(other):
520497
return np.array([self * x for x in other])
@@ -653,34 +630,6 @@ cdef class BaseOffset:
653630

654631
# ------------------------------------------------------------------
655632

656-
def apply_index(self, dtindex):
657-
"""
658-
Vectorized apply of DateOffset to DatetimeIndex.
659-
660-
.. deprecated:: 1.1.0
661-
662-
Use ``offset + dtindex`` instead.
663-
664-
Parameters
665-
----------
666-
index : DatetimeIndex
667-
668-
Returns
669-
-------
670-
DatetimeIndex
671-
672-
Raises
673-
------
674-
NotImplementedError
675-
When the specific offset subclass does not have a vectorized
676-
implementation.
677-
"""
678-
warnings.warn("'Offset.apply_index(other)' is deprecated. "
679-
"Use 'offset + other' instead.", FutureWarning)
680-
681-
res = self._apply_array(dtindex)
682-
return type(dtindex)(res)
683-
684633
def _apply(self, other):
685634
raise NotImplementedError("implemented by subclasses")
686635

@@ -821,22 +770,6 @@ cdef class BaseOffset:
821770
def nanos(self):
822771
raise ValueError(f"{self} is a non-fixed frequency")
823772

824-
def onOffset(self, dt) -> bool:
825-
warnings.warn(
826-
"onOffset is a deprecated, use is_on_offset instead.",
827-
FutureWarning,
828-
stacklevel=find_stack_level(inspect.currentframe()),
829-
)
830-
return self.is_on_offset(dt)
831-
832-
def isAnchored(self) -> bool:
833-
warnings.warn(
834-
"isAnchored is a deprecated, use is_anchored instead.",
835-
FutureWarning,
836-
stacklevel=find_stack_level(inspect.currentframe()),
837-
)
838-
return self.is_anchored()
839-
840773
def is_anchored(self) -> bool:
841774
# TODO: Does this make sense for the general case? It would help
842775
# if there were a canonical docstring for what is_anchored means.

pandas/tests/tseries/offsets/test_business_day.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,9 @@ def test_mul(self):
9090
def test_hash(self):
9191
assert hash(self.offset2) == hash(self.offset2)
9292

93-
def test_call(self):
94-
with tm.assert_produces_warning(FutureWarning):
95-
# GH#34171 DateOffset.__call__ is deprecated
96-
assert self.offset2(self.d) == datetime(2008, 1, 3)
97-
assert self.offset2(self.nd) == datetime(2008, 1, 3)
93+
def test_add_datetime(self):
94+
assert self.offset2 + self.d == datetime(2008, 1, 3)
95+
assert self.offset2 + self.nd == datetime(2008, 1, 3)
9896

9997
def testRollback1(self):
10098
assert self._offset(10).rollback(self.d) == self.d

pandas/tests/tseries/offsets/test_business_hour.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -168,16 +168,14 @@ def test_hash(self, offset_name):
168168
offset = getattr(self, offset_name)
169169
assert offset == offset
170170

171-
def test_call(self):
172-
with tm.assert_produces_warning(FutureWarning):
173-
# GH#34171 DateOffset.__call__ is deprecated
174-
assert self.offset1(self.d) == datetime(2014, 7, 1, 11)
175-
assert self.offset2(self.d) == datetime(2014, 7, 1, 13)
176-
assert self.offset3(self.d) == datetime(2014, 6, 30, 17)
177-
assert self.offset4(self.d) == datetime(2014, 6, 30, 14)
178-
assert self.offset8(self.d) == datetime(2014, 7, 1, 11)
179-
assert self.offset9(self.d) == datetime(2014, 7, 1, 22)
180-
assert self.offset10(self.d) == datetime(2014, 7, 1, 1)
171+
def test_add_datetime(self):
172+
assert self.offset1 + self.d == datetime(2014, 7, 1, 11)
173+
assert self.offset2 + self.d == datetime(2014, 7, 1, 13)
174+
assert self.offset3 + self.d == datetime(2014, 6, 30, 17)
175+
assert self.offset4 + self.d == datetime(2014, 6, 30, 14)
176+
assert self.offset8 + self.d == datetime(2014, 7, 1, 11)
177+
assert self.offset9 + self.d == datetime(2014, 7, 1, 22)
178+
assert self.offset10 + self.d == datetime(2014, 7, 1, 1)
181179

182180
def test_sub(self):
183181
# we have to override test_sub here because self.offset2 is not

pandas/tests/tseries/offsets/test_custom_business_hour.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
Nano,
1616
)
1717

18-
import pandas._testing as tm
1918
from pandas.tests.tseries.offsets.common import (
2019
Base,
2120
assert_offset_equal,
@@ -95,11 +94,9 @@ def test_hash(self):
9594
assert hash(self.offset1) == hash(self.offset1)
9695
assert hash(self.offset2) == hash(self.offset2)
9796

98-
def test_call(self):
99-
with tm.assert_produces_warning(FutureWarning):
100-
# GH#34171 DateOffset.__call__ is deprecated
101-
assert self.offset1(self.d) == datetime(2014, 7, 1, 11)
102-
assert self.offset2(self.d) == datetime(2014, 7, 1, 11)
97+
def test_add_dateime(self):
98+
assert self.offset1 + self.d == datetime(2014, 7, 1, 11)
99+
assert self.offset2 + self.d == datetime(2014, 7, 1, 11)
103100

104101
def testRollback1(self):
105102
assert self.offset1.rollback(self.d) == self.d

pandas/tests/tseries/offsets/test_custom_business_month.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,8 @@ def test_repr(self):
8181
assert repr(self.offset) == "<CustomBusinessMonthBegin>"
8282
assert repr(self.offset2) == "<2 * CustomBusinessMonthBegins>"
8383

84-
def test_call(self):
85-
with tm.assert_produces_warning(FutureWarning):
86-
# GH#34171 DateOffset.__call__ is deprecated
87-
assert self.offset2(self.d) == datetime(2008, 3, 3)
84+
def test_add_datetime(self):
85+
assert self.offset2 + self.d == datetime(2008, 3, 3)
8886

8987
def testRollback1(self):
9088
assert CDay(10).rollback(datetime(2007, 12, 31)) == datetime(2007, 12, 31)
@@ -271,10 +269,8 @@ def test_repr(self):
271269
assert repr(self.offset) == "<CustomBusinessMonthEnd>"
272270
assert repr(self.offset2) == "<2 * CustomBusinessMonthEnds>"
273271

274-
def test_call(self):
275-
with tm.assert_produces_warning(FutureWarning):
276-
# GH#34171 DateOffset.__call__ is deprecated
277-
assert self.offset2(self.d) == datetime(2008, 2, 29)
272+
def test_add_datetime(self):
273+
assert self.offset2 + self.d == datetime(2008, 2, 29)
278274

279275
def testRollback1(self):
280276
assert CDay(10).rollback(datetime(2007, 12, 31)) == datetime(2007, 12, 31)

pandas/tests/tseries/offsets/test_month.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,6 @@ def test_apply_index(self, case):
230230
result = offset + shift
231231
tm.assert_index_equal(result, exp)
232232

233-
with tm.assert_produces_warning(FutureWarning):
234-
result = offset.apply_index(shift)
235-
tm.assert_index_equal(result, exp)
236-
237233
on_offset_cases = [
238234
(datetime(2007, 12, 31), True),
239235
(datetime(2007, 12, 15), True),

pandas/tests/tseries/offsets/test_offsets.py

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -213,16 +213,6 @@ def _check_offsetfunc_works(self, offset, funcname, dt, expected, normalize=Fals
213213
with tm.assert_produces_warning(exp_warning):
214214
result = func(ts)
215215

216-
if exp_warning is None and funcname == "_apply":
217-
# GH#44522
218-
# Check in this particular case to avoid headaches with
219-
# testing for multiple warnings produced by the same call.
220-
with tm.assert_produces_warning(FutureWarning, match="apply is deprecated"):
221-
res2 = offset_s.apply(ts)
222-
223-
assert type(res2) is type(result)
224-
assert res2 == result
225-
226216
assert isinstance(result, Timestamp)
227217
if normalize is False:
228218
assert result == expected + Nano(5)
@@ -526,27 +516,6 @@ def test_pickle_dateoffset_odd_inputs(self):
526516
base_dt = datetime(2020, 1, 1)
527517
assert base_dt + off == base_dt + res
528518

529-
def test_onOffset_deprecated(self, offset_types, fixed_now_ts):
530-
# GH#30340 use idiomatic naming
531-
off = self._get_offset(offset_types)
532-
533-
ts = fixed_now_ts
534-
with tm.assert_produces_warning(FutureWarning):
535-
result = off.onOffset(ts)
536-
537-
expected = off.is_on_offset(ts)
538-
assert result == expected
539-
540-
def test_isAnchored_deprecated(self, offset_types):
541-
# GH#30340 use idiomatic naming
542-
off = self._get_offset(offset_types)
543-
544-
with tm.assert_produces_warning(FutureWarning):
545-
result = off.isAnchored()
546-
547-
expected = off.is_anchored()
548-
assert result == expected
549-
550519
def test_offsets_hashable(self, offset_types):
551520
# GH: 37267
552521
off = self._get_offset(offset_types)

0 commit comments

Comments
 (0)