@@ -36,7 +36,7 @@ from pandas._libs.tslibs.base cimport ABCTimestamp
36
36
from pandas._libs.tslibs.ccalendar import (
37
37
MONTH_ALIASES, MONTH_TO_CAL_NUM, weekday_to_int, int_to_weekday,
38
38
)
39
- from pandas._libs.tslibs.ccalendar cimport get_days_in_month, dayofweek
39
+ from pandas._libs.tslibs.ccalendar cimport DAY_NANOS, get_days_in_month, dayofweek
40
40
from pandas._libs.tslibs.conversion cimport (
41
41
convert_datetime_to_tsobject,
42
42
localize_pydatetime,
@@ -1067,11 +1067,7 @@ cdef class RelativeDeltaOffset(BaseOffset):
1067
1067
1068
1068
weeks = kwds.get(" weeks" , 0 ) * self .n
1069
1069
if weeks:
1070
- # integer addition on PeriodIndex is deprecated,
1071
- # so we directly use _time_shift instead
1072
- asper = index.to_period(" W" )
1073
- shifted = asper._time_shift(weeks)
1074
- index = shifted.to_timestamp() + index.to_perioddelta(" W" )
1070
+ index = index + timedelta(days = 7 * weeks)
1075
1071
1076
1072
timedelta_kwds = {
1077
1073
k: v
@@ -1383,7 +1379,9 @@ cdef class BusinessDay(BusinessMixin):
1383
1379
1384
1380
@apply_index_wraps
1385
1381
def apply_index (self , dtindex ):
1386
- time = dtindex.to_perioddelta(" D" )
1382
+ i8other = dtindex.asi8
1383
+ time = (i8other % DAY_NANOS).view(" timedelta64[ns]" )
1384
+
1387
1385
# to_period rolls forward to next BDay; track and
1388
1386
# reduce n where it does when rolling forward
1389
1387
asper = dtindex.to_period(" B" )
@@ -2276,6 +2274,7 @@ cdef class SemiMonthOffset(SingleConstructorOffset):
2276
2274
from pandas import Timedelta
2277
2275
2278
2276
dti = dtindex
2277
+ i8other = dtindex.asi8
2279
2278
days_from_start = dtindex.to_perioddelta(" M" ).asi8
2280
2279
delta = Timedelta(days = self .day_of_month - 1 ).value
2281
2280
@@ -2289,7 +2288,7 @@ cdef class SemiMonthOffset(SingleConstructorOffset):
2289
2288
roll = self ._get_roll(dtindex, before_day_of_month, after_day_of_month)
2290
2289
2291
2290
# isolate the time since it will be striped away one the next line
2292
- time = dtindex.to_perioddelta( " D " )
2291
+ time = (i8other % DAY_NANOS).view( " timedelta64[ns] " )
2293
2292
2294
2293
# apply the correct number of months
2295
2294
@@ -2506,10 +2505,9 @@ cdef class Week(SingleConstructorOffset):
2506
2505
if self .weekday is None :
2507
2506
# integer addition on PeriodIndex is deprecated,
2508
2507
# so we use _time_shift directly
2509
- asper = dtindex.to_period(" W" )
2510
-
2511
- shifted = asper._time_shift(self .n)
2512
- return shifted.to_timestamp() + dtindex.to_perioddelta(" W" )
2508
+ td = timedelta(days = 7 * self .n)
2509
+ td64 = np.timedelta64(td, " ns" )
2510
+ return dtindex + td64
2513
2511
else :
2514
2512
return self ._end_apply_index(dtindex)
2515
2513
@@ -2529,7 +2527,8 @@ cdef class Week(SingleConstructorOffset):
2529
2527
from pandas import Timedelta
2530
2528
from .frequencies import get_freq_code # TODO: avoid circular import
2531
2529
2532
- off = dtindex.to_perioddelta(" D" )
2530
+ i8other = dtindex.asi8
2531
+ off = (i8other % DAY_NANOS).view(" timedelta64" )
2533
2532
2534
2533
base, mult = get_freq_code(self .freqstr)
2535
2534
base_period = dtindex.to_period(base)
0 commit comments