@@ -40,6 +40,7 @@ from pandas._libs.tslibs.ccalendar cimport DAY_NANOS, get_days_in_month, dayofwe
40
40
from pandas._libs.tslibs.conversion cimport (
41
41
convert_datetime_to_tsobject,
42
42
localize_pydatetime,
43
+ normalize_i8_timestamps,
43
44
)
44
45
from pandas._libs.tslibs.nattype cimport NPY_NAT, c_NaT as NaT
45
46
from pandas._libs.tslibs.np_datetime cimport (
@@ -79,21 +80,14 @@ cdef bint _is_normalized(datetime dt):
79
80
def apply_index_wraps (func ):
80
81
# Note: normally we would use `@functools.wraps(func)`, but this does
81
82
# 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
90
85
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)
94
88
95
89
if self.normalize:
96
- result = result.to_period( ' D ' ).to_timestamp( )
90
+ result = normalize_i8_timestamps( result.view( " i8 " ), None )
97
91
return result
98
92
99
93
# do @functools.wraps(func ) manually since it doesn't work on cdef funcs
@@ -1889,7 +1883,7 @@ cdef class YearOffset(SingleConstructorOffset):
1889
1883
shifted = shift_quarters(
1890
1884
dtindex.asi8, self .n, self .month, self ._day_opt, modby = 12
1891
1885
)
1892
- return type (dtindex)._simple_new( shifted, dtype = dtindex.dtype)
1886
+ return shifted
1893
1887
1894
1888
1895
1889
cdef class BYearEnd(YearOffset):
@@ -2033,7 +2027,7 @@ cdef class QuarterOffset(SingleConstructorOffset):
2033
2027
shifted = shift_quarters(
2034
2028
dtindex.asi8, self .n, self .startingMonth, self ._day_opt
2035
2029
)
2036
- return type (dtindex)._simple_new( shifted, dtype = dtindex.dtype)
2030
+ return shifted
2037
2031
2038
2032
2039
2033
cdef class BQuarterEnd(QuarterOffset):
@@ -2139,7 +2133,7 @@ cdef class MonthOffset(SingleConstructorOffset):
2139
2133
@apply_index_wraps
2140
2134
def apply_index (self , dtindex ):
2141
2135
shifted = shift_months(dtindex.asi8, self .n, self ._day_opt)
2142
- return type (dtindex)._simple_new( shifted, dtype = dtindex.dtype)
2136
+ return shifted
2143
2137
2144
2138
cpdef __setstate__(self , state):
2145
2139
state.pop(" _use_relativedelta" , False )
@@ -2503,8 +2497,6 @@ cdef class Week(SingleConstructorOffset):
2503
2497
@apply_index_wraps
2504
2498
def apply_index (self , dtindex ):
2505
2499
if self .weekday is None :
2506
- # integer addition on PeriodIndex is deprecated,
2507
- # so we use _time_shift directly
2508
2500
td = timedelta(days = 7 * self .n)
2509
2501
td64 = np.timedelta64(td, " ns" )
2510
2502
return dtindex + td64
0 commit comments