@@ -134,13 +134,6 @@ class CacheableOffset(object):
134
134
_cacheable = True
135
135
136
136
137
- _kwds_use_relativedelta = (
138
- 'years' , 'months' , 'weeks' , 'days' ,
139
- 'year' , 'month' , 'week' , 'day' , 'weekday' ,
140
- 'hour' , 'minute' , 'second' , 'microsecond'
141
- )
142
-
143
-
144
137
def _determine_offset (kwds ):
145
138
# timedelta is used for sub-daily plural offsets and all singular
146
139
# offsets relativedelta is used for plural offsets of daily length or
@@ -150,6 +143,11 @@ def _determine_offset(kwds):
150
143
if k not in ('nanosecond' , 'nanoseconds' )
151
144
)
152
145
146
+ _kwds_use_relativedelta = (
147
+ 'years' , 'months' , 'weeks' , 'days' ,
148
+ 'year' , 'month' , 'week' , 'day' , 'weekday' ,
149
+ 'hour' , 'minute' , 'second' , 'microsecond'
150
+ )
153
151
if len (kwds_no_nanos ) > 0 :
154
152
if any (k in _kwds_use_relativedelta for k in kwds_no_nanos ):
155
153
offset = relativedelta (** kwds_no_nanos )
@@ -209,22 +207,25 @@ def __add__(date):
209
207
_adjust_dst = False
210
208
_typ = "dateoffset"
211
209
210
+ # default for prior pickles
211
+ normalize = False
212
+
212
213
def __setattr__ (self , name , value ):
213
214
# DateOffset needs to be effectively immutable in order for the
214
215
# caching in _cached_params to be correct.
215
- frozen = ['n' , '_offset' , 'normalize' , '_inc' ]
216
- if name in frozen and hasattr (self , name ):
217
- msg = '%s cannot change attribute %s' % (self .__class__ , name )
218
- raise TypeError (msg )
216
+ if hasattr (self , name ):
217
+ # Resetting any existing attribute clears the cache_readonly
218
+ # cache.
219
+ try :
220
+ cache = self ._cache
221
+ except AttributeError :
222
+ # if the cache_readonly cache has not been accessed yet,
223
+ # this attribute may not exist
224
+ pass
225
+ else :
226
+ cache .clear ()
219
227
object .__setattr__ (self , name , value )
220
228
221
- def __setstate__ (self , state ):
222
- """Reconstruct an instance from a pickled state"""
223
- self .__dict__ = state
224
- if 'normalize' not in state and not hasattr (self , 'normalize' ):
225
- # default for prior pickles
226
- self .normalize = False
227
-
228
229
def __init__ (self , n = 1 , normalize = False , ** kwds ):
229
230
self .n = int (n )
230
231
self .normalize = normalize
@@ -618,10 +619,6 @@ def __setstate__(self, state):
618
619
self .kwds ['holidays' ] = self .holidays = holidays
619
620
self .kwds ['weekmask' ] = state ['weekmask' ]
620
621
621
- if 'normalize' not in state :
622
- # default for prior pickles
623
- self .normalize = False
624
-
625
622
626
623
class BusinessDay (BusinessMixin , SingleConstructorOffset ):
627
624
"""
@@ -635,7 +632,6 @@ def __init__(self, n=1, normalize=False, **kwds):
635
632
self .normalize = normalize
636
633
self .kwds = kwds
637
634
self .offset = kwds .get ('offset' , timedelta (0 ))
638
- self ._offset = None
639
635
640
636
@property
641
637
def freqstr (self ):
@@ -754,7 +750,6 @@ def __init__(self, **kwds):
754
750
self .offset = kwds .get ('offset' , timedelta (0 ))
755
751
self .start = kwds .get ('start' , '09:00' )
756
752
self .end = kwds .get ('end' , '17:00' )
757
- self ._offset = None
758
753
759
754
def _validate_time (self , t_input ):
760
755
from datetime import time as dt_time
@@ -1032,7 +1027,6 @@ def __init__(self, n=1, normalize=False, weekmask='Mon Tue Wed Thu Fri',
1032
1027
self .kwds ['weekmask' ] = self .weekmask = weekmask
1033
1028
self .kwds ['holidays' ] = self .holidays = holidays
1034
1029
self .kwds ['calendar' ] = self .calendar = calendar
1035
- self ._offset = None
1036
1030
1037
1031
def get_calendar (self , weekmask , holidays , calendar ):
1038
1032
"""Generate busdaycalendar"""
@@ -1229,7 +1223,6 @@ def __init__(self, n=1, day_of_month=None, normalize=False, **kwds):
1229
1223
self .normalize = normalize
1230
1224
self .kwds = kwds
1231
1225
self .kwds ['day_of_month' ] = self .day_of_month
1232
- self ._offset = None
1233
1226
1234
1227
@classmethod
1235
1228
def _from_name (cls , suffix = None ):
@@ -1628,7 +1621,6 @@ def __init__(self, n=1, normalize=False, **kwds):
1628
1621
1629
1622
self ._inc = timedelta (weeks = 1 )
1630
1623
self .kwds = kwds
1631
- self ._offset = None
1632
1624
1633
1625
def isAnchored (self ):
1634
1626
return (self .n == 1 and self .weekday is not None )
@@ -1751,7 +1743,6 @@ def __init__(self, n=1, normalize=False, **kwds):
1751
1743
self .week )
1752
1744
1753
1745
self .kwds = kwds
1754
- self ._offset = None
1755
1746
1756
1747
@apply_wraps
1757
1748
def apply (self , other ):
@@ -1842,7 +1833,6 @@ def __init__(self, n=1, normalize=False, **kwds):
1842
1833
self .weekday )
1843
1834
1844
1835
self .kwds = kwds
1845
- self ._offset = None
1846
1836
1847
1837
@apply_wraps
1848
1838
def apply (self , other ):
@@ -1908,8 +1898,8 @@ def __init__(self, n=1, normalize=False, **kwds):
1908
1898
self .normalize = normalize
1909
1899
self .startingMonth = kwds .get ('startingMonth' ,
1910
1900
self ._default_startingMonth )
1901
+
1911
1902
self .kwds = kwds
1912
- self ._offset = None
1913
1903
1914
1904
def isAnchored (self ):
1915
1905
return (self .n == 1 and self .startingMonth is not None )
@@ -2032,7 +2022,6 @@ def __init__(self, n=1, normalize=False, **kwds):
2032
2022
self .startingMonth = kwds .get ('startingMonth' , 3 )
2033
2023
2034
2024
self .kwds = kwds
2035
- self ._offset = None
2036
2025
2037
2026
def isAnchored (self ):
2038
2027
return (self .n == 1 and self .startingMonth is not None )
@@ -2358,7 +2347,6 @@ def __init__(self, n=1, normalize=False, **kwds):
2358
2347
self .variation = kwds ["variation" ]
2359
2348
2360
2349
self .kwds = kwds
2361
- self ._offset = None
2362
2350
2363
2351
if self .n == 0 :
2364
2352
raise ValueError ('N cannot be 0' )
0 commit comments