@@ -1247,11 +1247,27 @@ cdef class BusinessMixin(SingleConstructorOffset):
1247
1247
1248
1248
cdef readonly:
1249
1249
timedelta _offset
1250
+ # Only Custom subclasses use weekmask, holiday, calendar
1251
+ object weekmask, holidays, calendar
1250
1252
1251
1253
def __init__ (self , n = 1 , normalize = False , offset = timedelta(0 )):
1252
1254
BaseOffset.__init__ (self , n, normalize)
1253
1255
self ._offset = offset
1254
1256
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
+
1255
1271
@property
1256
1272
def offset (self ):
1257
1273
"""
@@ -1276,6 +1292,18 @@ cdef class BusinessMixin(SingleConstructorOffset):
1276
1292
self ._offset = state.pop(" _offset" )
1277
1293
elif " offset" in state:
1278
1294
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
+
1279
1307
BaseOffset.__setstate__(self , state)
1280
1308
1281
1309
@@ -1785,25 +1813,6 @@ cdef class BusinessHour(BusinessMixin):
1785
1813
return False
1786
1814
1787
1815
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
-
1807
1816
cdef class WeekOfMonthMixin(SingleConstructorOffset):
1808
1817
"""
1809
1818
Mixin for methods common to WeekOfMonth and LastWeekOfMonth.
@@ -3252,7 +3261,7 @@ cdef class Easter(SingleConstructorOffset):
3252
3261
# Custom Offset classes
3253
3262
3254
3263
3255
- class CustomBusinessDay (CustomMixin , BusinessDay ):
3264
+ cdef class CustomBusinessDay(BusinessDay):
3256
3265
"""
3257
3266
DateOffset subclass representing custom business days excluding holidays.
3258
3267
@@ -3291,12 +3300,12 @@ class CustomBusinessDay(CustomMixin, BusinessDay):
3291
3300
offset = timedelta(0 ),
3292
3301
):
3293
3302
BusinessDay.__init__ (self , n, normalize, offset)
3294
- CustomMixin. __init__ ( self , weekmask, holidays, calendar)
3303
+ self ._init_custom( weekmask, holidays, calendar)
3295
3304
3296
- def __setstate__ (self , state ):
3305
+ cpdef __setstate__(self , state):
3297
3306
self .holidays = state.pop(" holidays" )
3298
3307
self .weekmask = state.pop(" weekmask" )
3299
- super () .__setstate__(state)
3308
+ BusinessDay .__setstate__(self , state)
3300
3309
3301
3310
@apply_wraps
3302
3311
def apply (self , other ):
@@ -3338,7 +3347,7 @@ class CustomBusinessDay(CustomMixin, BusinessDay):
3338
3347
return np.is_busday(day64, busdaycal = self .calendar)
3339
3348
3340
3349
3341
- class CustomBusinessHour (CustomMixin , BusinessHour ):
3350
+ class CustomBusinessHour (BusinessHour ):
3342
3351
"""
3343
3352
DateOffset subclass representing possibly n custom business days.
3344
3353
"""
@@ -3361,7 +3370,7 @@ class CustomBusinessHour(CustomMixin, BusinessHour):
3361
3370
offset = timedelta(0 ),
3362
3371
):
3363
3372
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)
3365
3374
3366
3375
def __reduce__ (self ):
3367
3376
# None for self.calendar bc np.busdaycalendar doesnt pickle nicely
@@ -3380,7 +3389,7 @@ class CustomBusinessHour(CustomMixin, BusinessHour):
3380
3389
)
3381
3390
3382
3391
3383
- class _CustomBusinessMonth (CustomMixin , BusinessMixin , MonthOffset ):
3392
+ class _CustomBusinessMonth (BusinessMixin , MonthOffset ):
3384
3393
"""
3385
3394
DateOffset subclass representing custom business month(s).
3386
3395
@@ -3420,7 +3429,7 @@ class _CustomBusinessMonth(CustomMixin, BusinessMixin, MonthOffset):
3420
3429
offset = timedelta(0 ),
3421
3430
):
3422
3431
BusinessMixin.__init__ (self , n, normalize, offset)
3423
- CustomMixin. __init__ ( self , weekmask, holidays, calendar)
3432
+ self ._init_custom( weekmask, holidays, calendar)
3424
3433
3425
3434
def __reduce__ (self ):
3426
3435
# None for self.calendar bc np.busdaycalendar doesnt pickle nicely
0 commit comments