@@ -368,12 +368,31 @@ class _BaseOffset(object):
368
368
if name not in [' n' , ' normalize' ]}
369
369
return {name: kwds[name] for name in kwds if kwds[name] is not None }
370
370
371
+ def __add__ (self , other ):
372
+ if getattr (other, " _typ" , None ) in [" datetimeindex" ,
373
+ " series" , " period" ]:
374
+ # defer to the other class's implementation
375
+ return other + self
376
+ try :
377
+ return self .apply(other)
378
+ except ApplyTypeError:
379
+ return NotImplemented
380
+
381
+ def __sub__ (self , other ):
382
+ if isinstance (other, datetime):
383
+ raise TypeError (' Cannot subtract datetime from offset.' )
384
+ elif type (other) == type (self ):
385
+ return type (self )(self .n - other.n, normalize = self .normalize,
386
+ ** self .kwds)
387
+ else : # pragma: no cover
388
+ return NotImplemented
389
+
371
390
def __call__ (self , other ):
372
391
return self .apply(other)
373
392
374
393
def __mul__ (self , other ):
375
- return self . __class__ (n = other * self .n, normalize = self .normalize,
376
- ** self .kwds)
394
+ return type ( self ) (n = other * self .n, normalize = self .normalize,
395
+ ** self .kwds)
377
396
378
397
def __neg__ (self ):
379
398
# Note: we are defering directly to __mul__ instead of __rmul__, as
@@ -495,6 +514,14 @@ class BaseOffset(_BaseOffset):
495
514
return - self + other
496
515
497
516
517
+ class _Tick (object ):
518
+ """
519
+ dummy class to mix into tseries.offsets.Tick so that in tslibs.period we
520
+ can do isinstance checks on _Tick and avoid importing tseries.offsets
521
+ """
522
+ pass
523
+
524
+
498
525
# ----------------------------------------------------------------------
499
526
# RelativeDelta Arithmetic
500
527
0 commit comments