Skip to content

BUG: fix pickling of Custom offsets in 3.6 #14685

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 26 additions & 24 deletions pandas/tseries/offsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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:
Expand Down