@@ -1247,11 +1247,27 @@ cdef class BusinessMixin(SingleConstructorOffset):
12471247
12481248 cdef readonly:
12491249 timedelta _offset
1250+ # Only Custom subclasses use weekmask, holiday, calendar
1251+ object weekmask, holidays, calendar
12501252
12511253 def __init__ (self , n = 1 , normalize = False , offset = timedelta(0 )):
12521254 BaseOffset.__init__ (self , n, normalize)
12531255 self ._offset = offset
12541256
1257+ cpdef _init_custom(self , weekmask, holidays, calendar):
1258+ """
1259+ Additional __init__ for Custom subclasses.
1260+ """
1261+ calendar, holidays = _get_calendar(
1262+ weekmask = weekmask, holidays = holidays, calendar = calendar
1263+ )
1264+ # Custom offset instances are identified by the
1265+ # following two attributes. See DateOffset._params()
1266+ # holidays, weekmask
1267+ self .weekmask = weekmask
1268+ self .holidays = holidays
1269+ self .calendar = calendar
1270+
12551271 @property
12561272 def offset (self ):
12571273 """
@@ -1276,6 +1292,18 @@ cdef class BusinessMixin(SingleConstructorOffset):
12761292 self ._offset = state.pop(" _offset" )
12771293 elif " offset" in state:
12781294 self ._offset = state.pop(" offset" )
1295+
1296+ if self ._prefix.startswith(" C" ):
1297+ # i.e. this is a Custom class
1298+ weekmask = state.pop(" weekmask" )
1299+ holidays = state.pop(" holidays" )
1300+ calendar, holidays = _get_calendar(weekmask = weekmask,
1301+ holidays = holidays,
1302+ calendar = None )
1303+ self .weekmask = weekmask
1304+ self .calendar = calendar
1305+ self .holidays = holidays
1306+
12791307 BaseOffset.__setstate__(self , state)
12801308
12811309
@@ -1785,25 +1813,6 @@ cdef class BusinessHour(BusinessMixin):
17851813 return False
17861814
17871815
1788- class CustomMixin :
1789- """
1790- Mixin for classes that define and validate calendar, holidays,
1791- and weekdays attributes.
1792- """
1793-
1794- def __init__ (self , weekmask , holidays , calendar ):
1795- calendar, holidays = _get_calendar(
1796- weekmask = weekmask, holidays = holidays, calendar = calendar
1797- )
1798- # Custom offset instances are identified by the
1799- # following two attributes. See DateOffset._params()
1800- # holidays, weekmask
1801-
1802- object .__setattr__ (self , " weekmask" , weekmask)
1803- object .__setattr__ (self , " holidays" , holidays)
1804- object .__setattr__ (self , " calendar" , calendar)
1805-
1806-
18071816cdef class WeekOfMonthMixin(SingleConstructorOffset):
18081817 """
18091818 Mixin for methods common to WeekOfMonth and LastWeekOfMonth.
@@ -3252,7 +3261,7 @@ cdef class Easter(SingleConstructorOffset):
32523261# Custom Offset classes
32533262
32543263
3255- class CustomBusinessDay (CustomMixin , BusinessDay ):
3264+ cdef class CustomBusinessDay(BusinessDay):
32563265 """
32573266 DateOffset subclass representing custom business days excluding holidays.
32583267
@@ -3291,12 +3300,12 @@ class CustomBusinessDay(CustomMixin, BusinessDay):
32913300 offset = timedelta(0 ),
32923301 ):
32933302 BusinessDay.__init__ (self , n, normalize, offset)
3294- CustomMixin. __init__ ( self , weekmask, holidays, calendar)
3303+ self ._init_custom( weekmask, holidays, calendar)
32953304
3296- def __setstate__ (self , state ):
3305+ cpdef __setstate__(self , state):
32973306 self .holidays = state.pop(" holidays" )
32983307 self .weekmask = state.pop(" weekmask" )
3299- super () .__setstate__(state)
3308+ BusinessDay .__setstate__(self , state)
33003309
33013310 @apply_wraps
33023311 def apply (self , other ):
@@ -3338,7 +3347,7 @@ class CustomBusinessDay(CustomMixin, BusinessDay):
33383347 return np.is_busday(day64, busdaycal = self .calendar)
33393348
33403349
3341- class CustomBusinessHour (CustomMixin , BusinessHour ):
3350+ class CustomBusinessHour (BusinessHour ):
33423351 """
33433352 DateOffset subclass representing possibly n custom business days.
33443353 """
@@ -3361,7 +3370,7 @@ class CustomBusinessHour(CustomMixin, BusinessHour):
33613370 offset = timedelta(0 ),
33623371 ):
33633372 BusinessHour.__init__ (self , n, normalize, start = start, end = end, offset = offset)
3364- CustomMixin. __init__ ( self , weekmask, holidays, calendar)
3373+ self ._init_custom( weekmask, holidays, calendar)
33653374
33663375 def __reduce__ (self ):
33673376 # None for self.calendar bc np.busdaycalendar doesnt pickle nicely
@@ -3380,7 +3389,7 @@ class CustomBusinessHour(CustomMixin, BusinessHour):
33803389 )
33813390
33823391
3383- class _CustomBusinessMonth (CustomMixin , BusinessMixin , MonthOffset ):
3392+ class _CustomBusinessMonth (BusinessMixin , MonthOffset ):
33843393 """
33853394 DateOffset subclass representing custom business month(s).
33863395
@@ -3420,7 +3429,7 @@ class _CustomBusinessMonth(CustomMixin, BusinessMixin, MonthOffset):
34203429 offset = timedelta(0 ),
34213430 ):
34223431 BusinessMixin.__init__ (self , n, normalize, offset)
3423- CustomMixin. __init__ ( self , weekmask, holidays, calendar)
3432+ self ._init_custom( weekmask, holidays, calendar)
34243433
34253434 def __reduce__ (self ):
34263435 # None for self.calendar bc np.busdaycalendar doesnt pickle nicely
0 commit comments