@@ -3786,7 +3786,7 @@ cdef inline void _shift_quarters(const int64_t[:] dtindex,
3786
3786
""" See shift_quarters.__doc__"""
3787
3787
cdef:
3788
3788
Py_ssize_t i
3789
- int months_since, compare_day, n
3789
+ int months_since, n
3790
3790
npy_datetimestruct dts
3791
3791
3792
3792
for i in range (count):
@@ -3798,18 +3798,7 @@ cdef inline void _shift_quarters(const int64_t[:] dtindex,
3798
3798
n = quarters
3799
3799
3800
3800
months_since = (dts.month - q1start_month) % modby
3801
- compare_day = get_day_of_month(& dts, day_opt)
3802
-
3803
- # offset semantics - if on the anchor point and going backwards
3804
- # shift to next
3805
- if n <= 0 and (months_since != 0 or
3806
- (months_since == 0 and dts.day > compare_day)):
3807
- # make sure to roll forward, so negate
3808
- n += 1
3809
- elif n > 0 and (months_since == 0 and dts.day < compare_day):
3810
- # pretend to roll back if on same month but
3811
- # before compare_day
3812
- n -= 1
3801
+ n = _roll_qtrday(& dts, n, months_since, day_opt)
3813
3802
3814
3803
dts.year = year_add_months(dts, modby * n - months_since)
3815
3804
dts.month = month_add_months(dts, modby * n - months_since)
@@ -4009,7 +3998,7 @@ cpdef int roll_convention(int other, int n, int compare) nogil:
4009
3998
4010
3999
4011
4000
def roll_qtrday (other: datetime , n: int , month: int ,
4012
- day_opt: object , modby: int = 3 ) -> int:
4001
+ day_opt: object , modby: int ) -> int:
4013
4002
"""
4014
4003
Possibly increment or decrement the number of periods to shift
4015
4004
based on rollforward/rollbackward conventions.
@@ -4037,25 +4026,30 @@ def roll_qtrday(other: datetime, n: int, month: int,
4037
4026
npy_datetimestruct dts
4038
4027
pydate_to_dtstruct(other , &dts )
4039
4028
4040
- # TODO: with small adjustments this could be used in shift_quarters
4041
-
4042
4029
if modby == 12:
4043
4030
# We care about the month-of-year , not month-of-quarter , so skip mod
4044
4031
months_since = other.month - month
4045
4032
else:
4046
4033
months_since = other.month % modby - month % modby
4047
4034
4035
+ return _roll_qtrday(&dts , n , months_since , day_opt )
4036
+
4037
+
4038
+ cdef inline int _roll_qtrday(npy_datetimestruct* dts ,
4039
+ int n ,
4040
+ int months_since ,
4041
+ str day_opt ) nogil except? -1:
4042
+ """See roll_qtrday.__doc__"""
4043
+
4048
4044
if n > 0:
4049
4045
if months_since < 0 or (months_since == 0 and
4050
- other.day < get_day_of_month(&dts ,
4051
- day_opt )):
4046
+ dts.day < get_day_of_month(dts , day_opt )):
4052
4047
# pretend to roll back if on same month but
4053
4048
# before compare_day
4054
4049
n -= 1
4055
4050
else :
4056
4051
if months_since > 0 or (months_since == 0 and
4057
- other.day > get_day_of_month(& dts,
4058
- day_opt)):
4052
+ dts.day > get_day_of_month(dts, day_opt)):
4059
4053
# make sure to roll forward, so negate
4060
4054
n += 1
4061
4055
return n
0 commit comments