@@ -3744,7 +3744,6 @@ cdef shift_quarters(
3744
3744
npy_datetimestruct dts
3745
3745
int count = len (dtindex)
3746
3746
int months_to_roll, months_since, n, compare_day
3747
- bint roll_check
3748
3747
int64_t[:] out = np.empty(count, dtype = " int64" )
3749
3748
3750
3749
if day_opt == " start" :
@@ -3886,7 +3885,6 @@ def shift_months(const int64_t[:] dtindex, int months, object day_opt=None):
3886
3885
npy_datetimestruct dts
3887
3886
int count = len (dtindex)
3888
3887
int months_to_roll
3889
- bint roll_check
3890
3888
int64_t[:] out = np.empty(count, dtype = " int64" )
3891
3889
3892
3890
if day_opt is None :
@@ -3903,10 +3901,6 @@ def shift_months(const int64_t[:] dtindex, int months, object day_opt=None):
3903
3901
dts.day = min (dts.day, get_days_in_month(dts.year, dts.month))
3904
3902
out[i] = dtstruct_to_dt64(& dts)
3905
3903
elif day_opt == " start" :
3906
- roll_check = False
3907
- if months <= 0 :
3908
- months += 1
3909
- roll_check = True
3910
3904
with nogil:
3911
3905
for i in range (count):
3912
3906
if dtindex[i] == NPY_NAT:
@@ -3915,22 +3909,19 @@ def shift_months(const int64_t[:] dtindex, int months, object day_opt=None):
3915
3909
3916
3910
dt64_to_dtstruct(dtindex[i], & dts)
3917
3911
months_to_roll = months
3912
+ compare_day = 1
3918
3913
3919
3914
# offset semantics - if on the anchor point and going backwards
3920
3915
# shift to next
3921
- if roll_check and dts.day == 1 :
3922
- months_to_roll -= 1
3916
+ months_to_roll = roll_convention( dts.day, months_to_roll,
3917
+ compare_day)
3923
3918
3924
3919
dts.year = year_add_months(dts, months_to_roll)
3925
3920
dts.month = month_add_months(dts, months_to_roll)
3926
3921
dts.day = 1
3927
3922
3928
3923
out[i] = dtstruct_to_dt64(& dts)
3929
3924
elif day_opt == " end" :
3930
- roll_check = False
3931
- if months > 0 :
3932
- months -= 1
3933
- roll_check = True
3934
3925
with nogil:
3935
3926
for i in range (count):
3936
3927
if dtindex[i] == NPY_NAT:
@@ -3939,12 +3930,12 @@ def shift_months(const int64_t[:] dtindex, int months, object day_opt=None):
3939
3930
3940
3931
dt64_to_dtstruct(dtindex[i], & dts)
3941
3932
months_to_roll = months
3933
+ compare_day = get_days_in_month(dts.year, dts.month)
3942
3934
3943
3935
# similar semantics - when adding shift forward by one
3944
3936
# month if already at an end of month
3945
- if roll_check and dts.day == get_days_in_month(dts.year,
3946
- dts.month):
3947
- months_to_roll += 1
3937
+ months_to_roll = roll_convention(dts.day, months_to_roll,
3938
+ compare_day)
3948
3939
3949
3940
dts.year = year_add_months(dts, months_to_roll)
3950
3941
dts.month = month_add_months(dts, months_to_roll)
0 commit comments