@@ -553,6 +553,32 @@ def _repr_attrs(self):
553
553
out += ': ' + ', ' .join (attrs )
554
554
return out
555
555
556
+ def __getstate__ (self ):
557
+ """Return a pickleable state"""
558
+ state = self .__dict__ .copy ()
559
+
560
+ # we don't want to actually pickle the calendar object
561
+ # as its a np.busyday; we recreate on deserilization
562
+ if 'calendar' in state :
563
+ del state ['calendar' ]
564
+ try :
565
+ state ['kwds' ].pop ('calendar' )
566
+ except KeyError :
567
+ pass
568
+
569
+ return state
570
+
571
+ def __setstate__ (self , state ):
572
+ """Reconstruct an instance from a pickled state"""
573
+ self .__dict__ = state
574
+ if 'weekmask' in state and 'holidays' in state :
575
+ calendar , holidays = self .get_calendar (weekmask = self .weekmask ,
576
+ holidays = self .holidays ,
577
+ calendar = None )
578
+ self .kwds ['calendar' ] = self .calendar = calendar
579
+ self .kwds ['holidays' ] = self .holidays = holidays
580
+ self .kwds ['weekmask' ] = state ['weekmask' ]
581
+
556
582
557
583
class BusinessDay (BusinessMixin , SingleConstructorOffset ):
558
584
"""
@@ -992,30 +1018,6 @@ def get_calendar(self, weekmask, holidays, calendar):
992
1018
busdaycalendar = np .busdaycalendar (** kwargs )
993
1019
return busdaycalendar , holidays
994
1020
995
- def __getstate__ (self ):
996
- """Return a pickleable state"""
997
- state = self .__dict__ .copy ()
998
- del state ['calendar' ]
999
-
1000
- # we don't want to actually pickle the calendar object
1001
- # as its a np.busyday; we recreate on deserilization
1002
- try :
1003
- state ['kwds' ].pop ('calendar' )
1004
- except :
1005
- pass
1006
-
1007
- return state
1008
-
1009
- def __setstate__ (self , state ):
1010
- """Reconstruct an instance from a pickled state"""
1011
- self .__dict__ = state
1012
- calendar , holidays = self .get_calendar (weekmask = self .weekmask ,
1013
- holidays = self .holidays ,
1014
- calendar = None )
1015
- self .kwds ['calendar' ] = self .calendar = calendar
1016
- self .kwds ['holidays' ] = self .holidays = holidays
1017
- self .kwds ['weekmask' ] = state ['weekmask' ]
1018
-
1019
1021
@apply_wraps
1020
1022
def apply (self , other ):
1021
1023
if self .n <= 0 :
0 commit comments