@@ -895,6 +895,13 @@ cdef class Tick(SingleConstructorOffset):
895
895
896
896
raise ApplyTypeError(f" Unhandled type: {type(other).__name__}" )
897
897
898
+ # --------------------------------------------------------------------
899
+ # Pickle Methods
900
+
901
+ def __setstate__ (self , state ):
902
+ self .n = state[" n" ]
903
+ self .normalize = False
904
+
898
905
899
906
cdef class Day(Tick):
900
907
_nanos_inc = 24 * 3600 * 1 _000_000_000
@@ -1998,6 +2005,11 @@ cdef class QuarterOffset(SingleConstructorOffset):
1998
2005
startingMonth = self ._default_starting_month
1999
2006
self .startingMonth = startingMonth
2000
2007
2008
+ cpdef __setstate__(self , state):
2009
+ self .startingMonth = state.pop(" startingMonth" )
2010
+ self .n = state.pop(" n" )
2011
+ self .normalize = state.pop(" normalize" )
2012
+
2001
2013
@classmethod
2002
2014
def _from_name (cls , suffix = None ):
2003
2015
kwargs = {}
@@ -2253,6 +2265,11 @@ cdef class SemiMonthOffset(SingleConstructorOffset):
2253
2265
f" got {self.day_of_month}"
2254
2266
)
2255
2267
2268
+ cpdef __setstate__(self , state):
2269
+ self .n = state.pop(" n" )
2270
+ self .normalize = state.pop(" normalize" )
2271
+ self .day_of_month = state.pop(" day_of_month" )
2272
+
2256
2273
@classmethod
2257
2274
def _from_name (cls , suffix = None ):
2258
2275
return cls (day_of_month = suffix)
@@ -2570,6 +2587,12 @@ cdef class WeekOfMonth(WeekOfMonthMixin):
2570
2587
if self .week < 0 or self .week > 3 :
2571
2588
raise ValueError (f" Week must be 0<=week<=3, got {self.week}" )
2572
2589
2590
+ cpdef __setstate__(self , state):
2591
+ self .n = state.pop(" n" )
2592
+ self .normalize = state.pop(" normalize" )
2593
+ self .weekday = state.pop(" weekday" )
2594
+ self .week = state.pop(" week" )
2595
+
2573
2596
def _get_offset_day (self , other: datetime ) -> int:
2574
2597
"""
2575
2598
Find the day in the same month as other that has the same
@@ -2629,6 +2652,12 @@ cdef class LastWeekOfMonth(WeekOfMonthMixin):
2629
2652
if self .n == 0 :
2630
2653
raise ValueError (" N cannot be 0" )
2631
2654
2655
+ cpdef __setstate__(self , state):
2656
+ self .n = state.pop(" n" )
2657
+ self .normalize = state.pop(" normalize" )
2658
+ self .weekday = state.pop(" weekday" )
2659
+ self .week = - 1
2660
+
2632
2661
def _get_offset_day (self , other: datetime ) -> int:
2633
2662
"""
2634
2663
Find the day in the same month as other that has the same
@@ -2680,6 +2709,12 @@ cdef class FY5253Mixin(SingleConstructorOffset):
2680
2709
if self .variation not in [" nearest" , " last" ]:
2681
2710
raise ValueError (f" {self.variation} is not a valid variation" )
2682
2711
2712
+ cpdef __setstate__(self , state):
2713
+ self .n = state.pop(" n" )
2714
+ self .normalize = state.pop(" normalize" )
2715
+ self .weekday = state.pop(" weekday" )
2716
+ self .variation = state.pop(" variation" )
2717
+
2683
2718
def is_anchored (self ) -> bool:
2684
2719
return (
2685
2720
self.n == 1 and self.startingMonth is not None and self.weekday is not None
@@ -2960,6 +2995,10 @@ cdef class FY5253Quarter(FY5253Mixin):
2960
2995
)
2961
2996
self .qtr_with_extra_week = qtr_with_extra_week
2962
2997
2998
+ cpdef __setstate__(self , state):
2999
+ FY5253Mixin.__setstate__(self , state)
3000
+ self .qtr_with_extra_week = state.pop(" qtr_with_extra_week" )
3001
+
2963
3002
@cache_readonly
2964
3003
def _offset (self ):
2965
3004
return FY5253(
@@ -3102,6 +3141,10 @@ cdef class Easter(SingleConstructorOffset):
3102
3141
Right now uses the revised method which is valid in years 1583-4099.
3103
3142
"""
3104
3143
3144
+ cpdef __setstate__(self , state):
3145
+ self .n = state.pop(" n" )
3146
+ self .normalize = state.pop(" normalize" )
3147
+
3105
3148
@apply_wraps
3106
3149
def apply (self , other: datetime ) -> datetime:
3107
3150
current_easter = easter(other.year)
0 commit comments