@@ -40,6 +40,7 @@ from pandas._libs.tslibs.ccalendar cimport DAY_NANOS, get_days_in_month, dayofwe
4040from pandas._libs.tslibs.conversion cimport (
4141 convert_datetime_to_tsobject,
4242 localize_pydatetime,
43+ normalize_i8_timestamps,
4344)
4445from pandas._libs.tslibs.nattype cimport NPY_NAT, c_NaT as NaT
4546from pandas._libs.tslibs.np_datetime cimport (
@@ -79,21 +80,14 @@ cdef bint _is_normalized(datetime dt):
7980def apply_index_wraps (func ):
8081 # Note: normally we would use `@functools.wraps(func)`, but this does
8182 # not play nicely with cython class methods
82- def wrapper (self , other ):
83-
84- is_index = not util.is_array(other._data)
85-
86- # operate on DatetimeArray
87- arr = other._data if is_index else other
88-
89- result = func(self , arr)
83+ def wrapper (self , other ) -> np.ndarray:
84+ # other is a DatetimeArray
9085
91- if is_index:
92- # Wrap DatetimeArray result back to DatetimeIndex
93- result = type (other)._simple_new(result, name = other.name)
86+ result = func(self , other)
87+ result = np.asarray(result)
9488
9589 if self.normalize:
96- result = result.to_period( ' D ' ).to_timestamp( )
90+ result = normalize_i8_timestamps( result.view( " i8 " ), None )
9791 return result
9892
9993 # do @functools.wraps(func ) manually since it doesn't work on cdef funcs
@@ -1889,7 +1883,7 @@ cdef class YearOffset(SingleConstructorOffset):
18891883 shifted = shift_quarters(
18901884 dtindex.asi8, self .n, self .month, self ._day_opt, modby = 12
18911885 )
1892- return type (dtindex)._simple_new( shifted, dtype = dtindex.dtype)
1886+ return shifted
18931887
18941888
18951889cdef class BYearEnd(YearOffset):
@@ -2033,7 +2027,7 @@ cdef class QuarterOffset(SingleConstructorOffset):
20332027 shifted = shift_quarters(
20342028 dtindex.asi8, self .n, self .startingMonth, self ._day_opt
20352029 )
2036- return type (dtindex)._simple_new( shifted, dtype = dtindex.dtype)
2030+ return shifted
20372031
20382032
20392033cdef class BQuarterEnd(QuarterOffset):
@@ -2139,7 +2133,7 @@ cdef class MonthOffset(SingleConstructorOffset):
21392133 @apply_index_wraps
21402134 def apply_index (self , dtindex ):
21412135 shifted = shift_months(dtindex.asi8, self .n, self ._day_opt)
2142- return type (dtindex)._simple_new( shifted, dtype = dtindex.dtype)
2136+ return shifted
21432137
21442138 cpdef __setstate__(self , state):
21452139 state.pop(" _use_relativedelta" , False )
@@ -2503,8 +2497,6 @@ cdef class Week(SingleConstructorOffset):
25032497 @apply_index_wraps
25042498 def apply_index (self , dtindex ):
25052499 if self .weekday is None :
2506- # integer addition on PeriodIndex is deprecated,
2507- # so we use _time_shift directly
25082500 td = timedelta(days = 7 * self .n)
25092501 td64 = np.timedelta64(td, " ns" )
25102502 return dtindex + td64
0 commit comments