diff --git a/pandas/tseries/offsets.py b/pandas/tseries/offsets.py index 2e3852a7edddd..efcde100d1ce7 100644 --- a/pandas/tseries/offsets.py +++ b/pandas/tseries/offsets.py @@ -553,6 +553,32 @@ def _repr_attrs(self): out += ': ' + ', '.join(attrs) return out + def __getstate__(self): + """Return a pickleable state""" + state = self.__dict__.copy() + + # we don't want to actually pickle the calendar object + # as its a np.busyday; we recreate on deserilization + if 'calendar' in state: + del state['calendar'] + try: + state['kwds'].pop('calendar') + except KeyError: + pass + + return state + + def __setstate__(self, state): + """Reconstruct an instance from a pickled state""" + self.__dict__ = state + if 'weekmask' in state and 'holidays' in state: + calendar, holidays = self.get_calendar(weekmask=self.weekmask, + holidays=self.holidays, + calendar=None) + self.kwds['calendar'] = self.calendar = calendar + self.kwds['holidays'] = self.holidays = holidays + self.kwds['weekmask'] = state['weekmask'] + class BusinessDay(BusinessMixin, SingleConstructorOffset): """ @@ -992,30 +1018,6 @@ def get_calendar(self, weekmask, holidays, calendar): busdaycalendar = np.busdaycalendar(**kwargs) return busdaycalendar, holidays - def __getstate__(self): - """Return a pickleable state""" - state = self.__dict__.copy() - del state['calendar'] - - # we don't want to actually pickle the calendar object - # as its a np.busyday; we recreate on deserilization - try: - state['kwds'].pop('calendar') - except: - pass - - return state - - def __setstate__(self, state): - """Reconstruct an instance from a pickled state""" - self.__dict__ = state - calendar, holidays = self.get_calendar(weekmask=self.weekmask, - holidays=self.holidays, - calendar=None) - self.kwds['calendar'] = self.calendar = calendar - self.kwds['holidays'] = self.holidays = holidays - self.kwds['weekmask'] = state['weekmask'] - @apply_wraps def apply(self, other): if self.n <= 0: