4
4
5
5
from pandas .core .common import _count_not_none
6
6
from pandas .tseries .tools import to_datetime
7
+ from pandas .util .decorators import cache_readonly
7
8
8
9
# import after tools, dateutil check
9
10
from dateutil .relativedelta import relativedelta
@@ -408,15 +409,15 @@ def __init__(self, n=1, **kwds):
408
409
raise Exception ('Day must be 0<=day<=6, got %d' %
409
410
self .weekday )
410
411
411
- self .delta = timedelta (weeks = 1 )
412
+ self ._inc = timedelta (weeks = 1 )
412
413
self .kwds = kwds
413
414
414
415
def isAnchored (self ):
415
416
return (self .n == 1 and self .weekday is not None )
416
417
417
418
def apply (self , other ):
418
419
if self .weekday is None :
419
- return other + self .n * self .delta
420
+ return other + self .n * self ._inc
420
421
421
422
if self .n > 0 :
422
423
k = self .n
@@ -425,14 +426,14 @@ def apply(self, other):
425
426
other = other + timedelta ((self .weekday - otherDay ) % 7 )
426
427
k = k - 1
427
428
for i in xrange (k ):
428
- other = other + self .delta
429
+ other = other + self ._inc
429
430
else :
430
431
k = self .n
431
432
otherDay = other .weekday ()
432
433
if otherDay != self .weekday :
433
434
other = other + timedelta ((self .weekday - otherDay ) % 7 )
434
435
for i in xrange (- k ):
435
- other = other - self .delta
436
+ other = other - self ._inc
436
437
return other
437
438
438
439
def onOffset (self , dt ):
@@ -919,7 +920,6 @@ def rule_code(self):
919
920
# Ticks
920
921
921
922
class Tick (DateOffset ):
922
- _delta = None
923
923
_inc = timedelta (microseconds = 1000 )
924
924
925
925
def __add__ (self , other ):
@@ -955,12 +955,9 @@ def __ne__(self, other):
955
955
else :
956
956
return DateOffset .__ne__ (self , other )
957
957
958
- @property
958
+ @cache_readonly
959
959
def delta (self ):
960
- if self ._delta is None :
961
- self ._delta = self .n * self ._inc
962
-
963
- return self ._delta
960
+ return self .n * self ._inc
964
961
965
962
@property
966
963
def nanos (self ):
0 commit comments