@@ -442,7 +442,7 @@ cdef class BaseOffset:
442
442
return np.array([self + x for x in other])
443
443
444
444
try :
445
- return self .apply (other)
445
+ return self ._apply (other)
446
446
except ApplyTypeError:
447
447
return NotImplemented
448
448
@@ -466,7 +466,17 @@ cdef class BaseOffset:
466
466
FutureWarning ,
467
467
stacklevel = 1 ,
468
468
)
469
- return self .apply(other)
469
+ return self ._apply(other)
470
+
471
+ def apply (self , other ):
472
+ # GH#44522
473
+ warnings.warn(
474
+ f" {type(self).__name__}.apply is deprecated and will be removed "
475
+ " in a future version. Use `offset + other` instead" ,
476
+ FutureWarning ,
477
+ stacklevel = 2 ,
478
+ )
479
+ return self ._apply(other)
470
480
471
481
def __mul__ (self , other ):
472
482
if util.is_array(other):
@@ -895,7 +905,7 @@ cdef class Tick(SingleConstructorOffset):
895
905
else :
896
906
return delta_to_tick(self .delta + other.delta)
897
907
try :
898
- return self .apply (other)
908
+ return self ._apply (other)
899
909
except ApplyTypeError:
900
910
# Includes pd.Period
901
911
return NotImplemented
@@ -904,7 +914,7 @@ cdef class Tick(SingleConstructorOffset):
904
914
f" the add operation between {self} and {other} will overflow"
905
915
) from err
906
916
907
- def apply (self , other ):
917
+ def _apply (self , other ):
908
918
# Timestamp can handle tz and nano sec, thus no need to use apply_wraps
909
919
if isinstance (other, _Timestamp):
910
920
# GH#15126
@@ -1047,7 +1057,7 @@ cdef class RelativeDeltaOffset(BaseOffset):
1047
1057
self .__dict__ .update(state)
1048
1058
1049
1059
@apply_wraps
1050
- def apply (self , other: datetime ) -> datetime:
1060
+ def _apply (self , other: datetime ) -> datetime:
1051
1061
if self._use_relativedelta:
1052
1062
other = _as_datetime(other)
1053
1063
@@ -1377,7 +1387,7 @@ cdef class BusinessDay(BusinessMixin):
1377
1387
return " +" + repr (self .offset)
1378
1388
1379
1389
@apply_wraps
1380
- def apply (self , other ):
1390
+ def _apply (self , other ):
1381
1391
if PyDateTime_Check(other):
1382
1392
n = self .n
1383
1393
wday = other.weekday()
@@ -1690,7 +1700,7 @@ cdef class BusinessHour(BusinessMixin):
1690
1700
return dt
1691
1701
1692
1702
@apply_wraps
1693
- def apply (self , other: datetime ) -> datetime:
1703
+ def _apply (self , other: datetime ) -> datetime:
1694
1704
# used for detecting edge condition
1695
1705
nanosecond = getattr (other, " nanosecond" , 0 )
1696
1706
# reset timezone and nanosecond
@@ -1839,7 +1849,7 @@ cdef class WeekOfMonthMixin(SingleConstructorOffset):
1839
1849
raise ValueError (f" Day must be 0<=day<=6, got {weekday}" )
1840
1850
1841
1851
@apply_wraps
1842
- def apply (self , other: datetime ) -> datetime:
1852
+ def _apply (self , other: datetime ) -> datetime:
1843
1853
compare_day = self ._get_offset_day(other)
1844
1854
1845
1855
months = self .n
@@ -1919,7 +1929,7 @@ cdef class YearOffset(SingleConstructorOffset):
1919
1929
return get_day_of_month(&dts , self._day_opt )
1920
1930
1921
1931
@apply_wraps
1922
- def apply (self , other: datetime ) -> datetime:
1932
+ def _apply (self , other: datetime ) -> datetime:
1923
1933
years = roll_qtrday(other, self .n, self .month, self ._day_opt, modby = 12 )
1924
1934
months = years * 12 + (self .month - other.month)
1925
1935
return shift_month(other , months , self._day_opt )
@@ -2068,7 +2078,7 @@ cdef class QuarterOffset(SingleConstructorOffset):
2068
2078
return mod_month == 0 and dt.day == self ._get_offset_day(dt)
2069
2079
2070
2080
@apply_wraps
2071
- def apply (self , other: datetime ) -> datetime:
2081
+ def _apply (self , other: datetime ) -> datetime:
2072
2082
# months_since: find the calendar quarter containing other.month ,
2073
2083
# e.g. if other.month == 8, the calendar quarter is [Jul , Aug , Sep].
2074
2084
# Then find the month in that quarter containing an is_on_offset date for
@@ -2195,7 +2205,7 @@ cdef class MonthOffset(SingleConstructorOffset):
2195
2205
return dt.day == self ._get_offset_day(dt)
2196
2206
2197
2207
@apply_wraps
2198
- def apply (self , other: datetime ) -> datetime:
2208
+ def _apply (self , other: datetime ) -> datetime:
2199
2209
compare_day = self ._get_offset_day(other)
2200
2210
n = roll_convention(other.day, self .n, compare_day)
2201
2211
return shift_month(other , n , self._day_opt )
@@ -2313,7 +2323,7 @@ cdef class SemiMonthOffset(SingleConstructorOffset):
2313
2323
return self._prefix + suffix
2314
2324
2315
2325
@apply_wraps
2316
- def apply (self , other: datetime ) -> datetime:
2326
+ def _apply (self , other: datetime ) -> datetime:
2317
2327
is_start = isinstance (self , SemiMonthBegin)
2318
2328
2319
2329
# shift `other` to self.day_of_month , incrementing `n` if necessary
@@ -2488,7 +2498,7 @@ cdef class Week(SingleConstructorOffset):
2488
2498
return self.n == 1 and self.weekday is not None
2489
2499
2490
2500
@apply_wraps
2491
- def apply (self , other ):
2501
+ def _apply (self , other ):
2492
2502
if self .weekday is None :
2493
2503
return other + self .n * self ._inc
2494
2504
@@ -2839,7 +2849,7 @@ cdef class FY5253(FY5253Mixin):
2839
2849
return year_end == dt
2840
2850
2841
2851
@apply_wraps
2842
- def apply (self , other: datetime ) -> datetime:
2852
+ def _apply (self , other: datetime ) -> datetime:
2843
2853
norm = Timestamp(other).normalize()
2844
2854
2845
2855
n = self .n
@@ -3088,7 +3098,7 @@ cdef class FY5253Quarter(FY5253Mixin):
3088
3098
return start, num_qtrs, tdelta
3089
3099
3090
3100
@apply_wraps
3091
- def apply (self , other: datetime ) -> datetime:
3101
+ def _apply (self , other: datetime ) -> datetime:
3092
3102
# Note: self.n == 0 is not allowed.
3093
3103
3094
3104
n = self .n
@@ -3179,7 +3189,7 @@ cdef class Easter(SingleConstructorOffset):
3179
3189
self .normalize = state.pop(" normalize" )
3180
3190
3181
3191
@apply_wraps
3182
- def apply (self , other: datetime ) -> datetime:
3192
+ def _apply (self , other: datetime ) -> datetime:
3183
3193
current_easter = easter(other.year)
3184
3194
current_easter = datetime(
3185
3195
current_easter.year, current_easter.month, current_easter.day
@@ -3258,7 +3268,7 @@ cdef class CustomBusinessDay(BusinessDay):
3258
3268
BusinessDay.__setstate__(self , state)
3259
3269
3260
3270
@apply_wraps
3261
- def apply (self , other ):
3271
+ def _apply (self , other ):
3262
3272
if self .n <= 0 :
3263
3273
roll = " forward"
3264
3274
else :
@@ -3421,7 +3431,7 @@ cdef class _CustomBusinessMonth(BusinessMixin):
3421
3431
return roll_func
3422
3432
3423
3433
@apply_wraps
3424
- def apply (self , other: datetime ) -> datetime:
3434
+ def _apply (self , other: datetime ) -> datetime:
3425
3435
# First move to month offset
3426
3436
cur_month_offset_date = self .month_roll(other)
3427
3437
0 commit comments