@@ -110,33 +110,6 @@ cdef bint _is_normalized(datetime dt):
110
110
return True
111
111
112
112
113
- def apply_wrapper_core (func , self , other ) -> ndarray:
114
- result = func(self , other)
115
- result = np.asarray(result)
116
-
117
- if self.normalize:
118
- # TODO: Avoid circular/runtime import
119
- from .vectorized import normalize_i8_timestamps
120
- reso = get_unit_from_dtype(other.dtype)
121
- result = normalize_i8_timestamps(result.view(" i8" ), None , reso = reso)
122
-
123
- return result
124
-
125
-
126
- def apply_array_wraps(func ):
127
- # Note: normally we would use `@functools.wraps(func)`, but this does
128
- # not play nicely with cython class methods
129
- def wrapper (self , other ) -> np.ndarray:
130
- # other is a DatetimeArray
131
- result = apply_wrapper_core(func, self , other)
132
- return result
133
-
134
- # do @functools.wraps(func ) manually since it doesn't work on cdef funcs
135
- wrapper.__name__ = func.__name__
136
- wrapper.__doc__ = func.__doc__
137
- return wrapper
138
-
139
-
140
113
def apply_wraps (func ):
141
114
# Note: normally we would use `@functools.wraps(func)`, but this does
142
115
# not play nicely with cython class methods
@@ -644,8 +617,9 @@ cdef class BaseOffset:
644
617
def _apply(self , other ):
645
618
raise NotImplementedError (" implemented by subclasses" )
646
619
647
- @apply_array_wraps
648
- def _apply_array (self , dtarr ):
620
+ def _apply_array (self , dtarr: np.ndarray ) -> np.ndarray:
621
+ # NB: _apply_array does not handle respecting `self.normalize`, the
622
+ # caller (DatetimeArray ) handles that in post-processing.
649
623
raise NotImplementedError(
650
624
f"DateOffset subclass {type(self ).__name__} "
651
625
"does not have a vectorized implementation"
@@ -1399,8 +1373,7 @@ cdef class RelativeDeltaOffset(BaseOffset):
1399
1373
" applied vectorized"
1400
1374
)
1401
1375
1402
- @apply_array_wraps
1403
- def _apply_array (self , dtarr ):
1376
+ def _apply_array (self , dtarr: np.ndarray ) -> np.ndarray:
1404
1377
reso = get_unit_from_dtype(dtarr.dtype)
1405
1378
dt64other = np.asarray(dtarr)
1406
1379
@@ -1814,8 +1787,7 @@ cdef class BusinessDay(BusinessMixin):
1814
1787
days = n + 2
1815
1788
return days
1816
1789
1817
- @apply_array_wraps
1818
- def _apply_array (self , dtarr ):
1790
+ def _apply_array (self , dtarr: np.ndarray ) -> np.ndarray:
1819
1791
i8other = dtarr.view(" i8" )
1820
1792
reso = get_unit_from_dtype(dtarr.dtype)
1821
1793
res = self ._shift_bdays(i8other, reso = reso)
@@ -2361,8 +2333,7 @@ cdef class YearOffset(SingleConstructorOffset):
2361
2333
months = years * 12 + (self .month - other.month)
2362
2334
return shift_month(other , months , self._day_opt )
2363
2335
2364
- @apply_array_wraps
2365
- def _apply_array(self , dtarr ):
2336
+ def _apply_array(self , dtarr: np.ndarray ) -> np.ndarray:
2366
2337
reso = get_unit_from_dtype(dtarr.dtype)
2367
2338
shifted = shift_quarters(
2368
2339
dtarr.view(" i8" ), self .n, self .month, self ._day_opt, modby = 12 , reso = reso
@@ -2613,8 +2584,7 @@ cdef class QuarterOffset(SingleConstructorOffset):
2613
2584
months = qtrs * 3 - months_since
2614
2585
return shift_month(other , months , self._day_opt )
2615
2586
2616
- @apply_array_wraps
2617
- def _apply_array(self , dtarr ):
2587
+ def _apply_array(self , dtarr: np.ndarray ) -> np.ndarray:
2618
2588
reso = get_unit_from_dtype(dtarr.dtype)
2619
2589
shifted = shift_quarters(
2620
2590
dtarr.view(" i8" ),
@@ -2798,8 +2768,7 @@ cdef class MonthOffset(SingleConstructorOffset):
2798
2768
n = roll_convention(other.day, self .n, compare_day)
2799
2769
return shift_month(other , n , self._day_opt )
2800
2770
2801
- @apply_array_wraps
2802
- def _apply_array(self , dtarr ):
2771
+ def _apply_array(self , dtarr: np.ndarray ) -> np.ndarray:
2803
2772
reso = get_unit_from_dtype(dtarr.dtype)
2804
2773
shifted = shift_months(dtarr.view(" i8" ), self .n, self ._day_opt, reso = reso)
2805
2774
return shifted
@@ -3029,10 +2998,9 @@ cdef class SemiMonthOffset(SingleConstructorOffset):
3029
2998
3030
2999
return shift_month(other, months, to_day)
3031
3000
3032
- @apply_array_wraps
3033
3001
@ cython.wraparound (False )
3034
3002
@ cython.boundscheck (False )
3035
- def _apply_array (self , dtarr ) :
3003
+ def _apply_array (self , dtarr: np. ndarray ) -> np.ndarray :
3036
3004
cdef:
3037
3005
ndarray i8other = dtarr.view(" i8" )
3038
3006
Py_ssize_t i , count = dtarr.size
@@ -3254,8 +3222,7 @@ cdef class Week(SingleConstructorOffset):
3254
3222
3255
3223
return other + timedelta(weeks = k)
3256
3224
3257
- @apply_array_wraps
3258
- def _apply_array (self , dtarr ):
3225
+ def _apply_array (self , dtarr: np.ndarray ) -> np.ndarray:
3259
3226
if self.weekday is None:
3260
3227
td = timedelta(days = 7 * self .n)
3261
3228
unit = np.datetime_data(dtarr.dtype)[0 ]
0 commit comments