@@ -288,6 +288,7 @@ def isAnchored(self):
288
288
# if there were a canonical docstring for what isAnchored means.
289
289
return (self .n == 1 )
290
290
291
+ @cache_readonly
291
292
def _params (self ):
292
293
all_paras = self .__dict__ .copy ()
293
294
if 'holidays' in all_paras and not all_paras ['holidays' ]:
@@ -322,8 +323,6 @@ def name(self):
322
323
return self .rule_code
323
324
324
325
def __eq__ (self , other ):
325
- if other is None :
326
- return False
327
326
328
327
if isinstance (other , compat .string_types ):
329
328
from pandas .tseries .frequencies import to_offset
@@ -333,13 +332,13 @@ def __eq__(self, other):
333
332
if not isinstance (other , DateOffset ):
334
333
return False
335
334
336
- return self ._params () == other ._params ()
335
+ return self ._params == other ._params
337
336
338
337
def __ne__ (self , other ):
339
338
return not self == other
340
339
341
340
def __hash__ (self ):
342
- return hash (self ._params () )
341
+ return hash (self ._params )
343
342
344
343
def __add__ (self , other ):
345
344
if isinstance (other , (ABCDatetimeIndex , ABCSeries )):
@@ -397,7 +396,7 @@ def _prefix(self):
397
396
def rule_code (self ):
398
397
return self ._prefix
399
398
400
- @property
399
+ @cache_readonly
401
400
def freqstr (self ):
402
401
try :
403
402
code = self .rule_code
@@ -601,7 +600,7 @@ def next_bday(self):
601
600
else :
602
601
return BusinessDay (n = nb_offset )
603
602
604
- # TODO: Cache this once offsets are immutable
603
+ @ cache_readonly
605
604
def _get_daytime_flag (self ):
606
605
if self .start == self .end :
607
606
raise ValueError ('start and end must not be the same' )
@@ -643,12 +642,12 @@ def _prev_opening_time(self, other):
643
642
return datetime (other .year , other .month , other .day ,
644
643
self .start .hour , self .start .minute )
645
644
646
- # TODO: cache this once offsets are immutable
645
+ @ cache_readonly
647
646
def _get_business_hours_by_sec (self ):
648
647
"""
649
648
Return business hours in a day by seconds.
650
649
"""
651
- if self ._get_daytime_flag () :
650
+ if self ._get_daytime_flag :
652
651
# create dummy datetime to calculate businesshours in a day
653
652
dtstart = datetime (2014 , 4 , 1 , self .start .hour , self .start .minute )
654
653
until = datetime (2014 , 4 , 1 , self .end .hour , self .end .minute )
@@ -662,7 +661,7 @@ def _get_business_hours_by_sec(self):
662
661
def rollback (self , dt ):
663
662
"""Roll provided date backward to next offset only if not on offset"""
664
663
if not self .onOffset (dt ):
665
- businesshours = self ._get_business_hours_by_sec ()
664
+ businesshours = self ._get_business_hours_by_sec
666
665
if self .n >= 0 :
667
666
dt = self ._prev_opening_time (
668
667
dt ) + timedelta (seconds = businesshours )
@@ -683,9 +682,8 @@ def rollforward(self, dt):
683
682
684
683
@apply_wraps
685
684
def apply (self , other ):
686
- # calculate here because offset is not immutable
687
- daytime = self ._get_daytime_flag ()
688
- businesshours = self ._get_business_hours_by_sec ()
685
+ daytime = self ._get_daytime_flag
686
+ businesshours = self ._get_business_hours_by_sec
689
687
bhdelta = timedelta (seconds = businesshours )
690
688
691
689
if isinstance (other , datetime ):
@@ -766,7 +764,7 @@ def onOffset(self, dt):
766
764
dt .minute , dt .second , dt .microsecond )
767
765
# Valid BH can be on the different BusinessDay during midnight
768
766
# Distinguish by the time spent from previous opening time
769
- businesshours = self ._get_business_hours_by_sec ()
767
+ businesshours = self ._get_business_hours_by_sec
770
768
return self ._onOffset (dt , businesshours )
771
769
772
770
def _onOffset (self , dt , businesshours ):
@@ -2203,13 +2201,12 @@ def __eq__(self, other):
2203
2201
if isinstance (other , Tick ):
2204
2202
return self .delta == other .delta
2205
2203
else :
2206
- # TODO: Are there cases where this should raise TypeError?
2207
2204
return False
2208
2205
2209
2206
# This is identical to DateOffset.__hash__, but has to be redefined here
2210
2207
# for Python 3, because we've redefined __eq__.
2211
2208
def __hash__ (self ):
2212
- return hash (self ._params () )
2209
+ return hash (self ._params )
2213
2210
2214
2211
def __ne__ (self , other ):
2215
2212
if isinstance (other , compat .string_types ):
@@ -2220,7 +2217,6 @@ def __ne__(self, other):
2220
2217
if isinstance (other , Tick ):
2221
2218
return self .delta != other .delta
2222
2219
else :
2223
- # TODO: Are there cases where this should raise TypeError?
2224
2220
return True
2225
2221
2226
2222
@property
0 commit comments