@@ -558,7 +558,7 @@ cdef class BaseOffset:
558
558
559
559
def _get_offset_day (self , other: datetime ) -> int:
560
560
# subclass must implement `_day_opt`; calling from the base class
561
- # will raise NotImplementedError .
561
+ # will implicitly assume day_opt = " business_end " , see get_day_of_month .
562
562
cdef:
563
563
npy_datetimestruct dts
564
564
pydate_to_dtstruct(other , &dts )
@@ -3611,7 +3611,6 @@ def shift_months(const int64_t[:] dtindex, int months, object day_opt=None):
3611
3611
out[i] = dtstruct_to_dt64(& dts)
3612
3612
elif day_opt in [" start" , " end" , " business_start" , " business_end" ]:
3613
3613
_shift_months(dtindex, out, count, months, day_opt)
3614
-
3615
3614
else :
3616
3615
raise ValueError (" day must be None, 'start', 'end', "
3617
3616
" 'business_start', or 'business_end'" )
@@ -3801,7 +3800,7 @@ def shift_month(stamp: datetime, months: int, day_opt: object=None) -> datetime:
3801
3800
return stamp.replace(year = year, month = month, day = day)
3802
3801
3803
3802
3804
- cdef inline int get_day_of_month(npy_datetimestruct* dts, day_opt) nogil except ? - 1 :
3803
+ cdef inline int get_day_of_month(npy_datetimestruct* dts, str day_opt) nogil:
3805
3804
"""
3806
3805
Find the day in `other`'s month that satisfies a DateOffset's is_on_offset
3807
3806
policy, as described by the `day_opt` argument.
@@ -3827,27 +3826,23 @@ cdef inline int get_day_of_month(npy_datetimestruct* dts, day_opt) nogil except?
3827
3826
>>> get_day_of_month(other, 'end')
3828
3827
30
3829
3828
3829
+ Notes
3830
+ -----
3831
+ Caller is responsible for ensuring one of the four accepted day_opt values
3832
+ is passed.
3830
3833
"""
3831
- cdef:
3832
- int days_in_month
3833
3834
3834
3835
if day_opt == " start" :
3835
3836
return 1
3836
3837
elif day_opt == " end" :
3837
- days_in_month = get_days_in_month(dts.year, dts.month)
3838
- return days_in_month
3838
+ return get_days_in_month(dts.year, dts.month)
3839
3839
elif day_opt == " business_start" :
3840
3840
# first business day of month
3841
3841
return get_firstbday(dts.year, dts.month)
3842
- elif day_opt == " business_end" :
3842
+ else :
3843
+ # i.e. day_opt == "business_end":
3843
3844
# last business day of month
3844
3845
return get_lastbday(dts.year, dts.month)
3845
- elif day_opt is not None :
3846
- raise ValueError (day_opt)
3847
- elif day_opt is None :
3848
- # Note: unlike `shift_month`, get_day_of_month does not
3849
- # allow day_opt = None
3850
- raise NotImplementedError
3851
3846
3852
3847
3853
3848
cpdef int roll_convention(int other, int n, int compare) nogil:
@@ -3901,6 +3896,10 @@ def roll_qtrday(other: datetime, n: int, month: int,
3901
3896
cdef:
3902
3897
int months_since
3903
3898
npy_datetimestruct dts
3899
+
3900
+ if day_opt not in ["start", "end", "business_start", "business_end"]:
3901
+ raise ValueError(day_opt )
3902
+
3904
3903
pydate_to_dtstruct(other , &dts )
3905
3904
3906
3905
if modby == 12:
0 commit comments