Skip to content

Commit 27f7c2b

Browse files
jbrockmendeljreback
authored andcommitted
remove daytime attr, move getstate and setstate to base class (#21533)
1 parent 71c53f0 commit 27f7c2b

File tree

2 files changed

+39
-40
lines changed

2 files changed

+39
-40
lines changed

pandas/_libs/tslibs/offsets.pyx

+39
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,45 @@ class _BaseOffset(object):
379379
'got {n}'.format(n=n))
380380
return nint
381381

382+
def __setstate__(self, state):
383+
"""Reconstruct an instance from a pickled state"""
384+
if 'offset' in state:
385+
# Older (<0.22.0) versions have offset attribute instead of _offset
386+
if '_offset' in state: # pragma: no cover
387+
raise AssertionError('Unexpected key `_offset`')
388+
state['_offset'] = state.pop('offset')
389+
state['kwds']['offset'] = state['_offset']
390+
391+
if '_offset' in state and not isinstance(state['_offset'], timedelta):
392+
# relativedelta, we need to populate using its kwds
393+
offset = state['_offset']
394+
odict = offset.__dict__
395+
kwds = {key: odict[key] for key in odict if odict[key]}
396+
state.update(kwds)
397+
398+
self.__dict__ = state
399+
if 'weekmask' in state and 'holidays' in state:
400+
calendar, holidays = _get_calendar(weekmask=self.weekmask,
401+
holidays=self.holidays,
402+
calendar=None)
403+
self.calendar = calendar
404+
self.holidays = holidays
405+
406+
def __getstate__(self):
407+
"""Return a pickleable state"""
408+
state = self.__dict__.copy()
409+
410+
# we don't want to actually pickle the calendar object
411+
# as its a np.busyday; we recreate on deserilization
412+
if 'calendar' in state:
413+
del state['calendar']
414+
try:
415+
state['kwds'].pop('calendar')
416+
except KeyError:
417+
pass
418+
419+
return state
420+
382421

383422
class BaseOffset(_BaseOffset):
384423
# Here we add __rfoo__ methods that don't play well with cdef classes

pandas/tseries/offsets.py

-40
Original file line numberDiff line numberDiff line change
@@ -423,30 +423,6 @@ def _offset_str(self):
423423
def nanos(self):
424424
raise ValueError("{name} is a non-fixed frequency".format(name=self))
425425

426-
def __setstate__(self, state):
427-
"""Reconstruct an instance from a pickled state"""
428-
if 'offset' in state:
429-
# Older (<0.22.0) versions have offset attribute instead of _offset
430-
if '_offset' in state: # pragma: no cover
431-
raise AssertionError('Unexpected key `_offset`')
432-
state['_offset'] = state.pop('offset')
433-
state['kwds']['offset'] = state['_offset']
434-
435-
if '_offset' in state and not isinstance(state['_offset'], timedelta):
436-
# relativedelta, we need to populate using its kwds
437-
offset = state['_offset']
438-
odict = offset.__dict__
439-
kwds = {key: odict[key] for key in odict if odict[key]}
440-
state.update(kwds)
441-
442-
self.__dict__ = state
443-
if 'weekmask' in state and 'holidays' in state:
444-
calendar, holidays = _get_calendar(weekmask=self.weekmask,
445-
holidays=self.holidays,
446-
calendar=None)
447-
self.calendar = calendar
448-
self.holidays = holidays
449-
450426

451427
class SingleConstructorOffset(DateOffset):
452428
@classmethod
@@ -494,21 +470,6 @@ def _repr_attrs(self):
494470
out += ': ' + ', '.join(attrs)
495471
return out
496472

497-
def __getstate__(self):
498-
"""Return a pickleable state"""
499-
state = self.__dict__.copy()
500-
501-
# we don't want to actually pickle the calendar object
502-
# as its a np.busyday; we recreate on deserilization
503-
if 'calendar' in state:
504-
del state['calendar']
505-
try:
506-
state['kwds'].pop('calendar')
507-
except KeyError:
508-
pass
509-
510-
return state
511-
512473

513474
class BusinessDay(BusinessMixin, SingleConstructorOffset):
514475
"""
@@ -690,7 +651,6 @@ def _get_business_hours_by_sec(self):
690651
until = datetime(2014, 4, 1, self.end.hour, self.end.minute)
691652
return (until - dtstart).total_seconds()
692653
else:
693-
self.daytime = False
694654
dtstart = datetime(2014, 4, 1, self.start.hour, self.start.minute)
695655
until = datetime(2014, 4, 2, self.end.hour, self.end.minute)
696656
return (until - dtstart).total_seconds()

0 commit comments

Comments
 (0)