@@ -368,12 +368,31 @@ class _BaseOffset(object):
368368 if name not in [' n' , ' normalize' ]}
369369 return {name: kwds[name] for name in kwds if kwds[name] is not None }
370370
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+
371390 def __call__ (self , other ):
372391 return self .apply(other)
373392
374393 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)
377396
378397 def __neg__ (self ):
379398 # Note: we are defering directly to __mul__ instead of __rmul__, as
@@ -495,6 +514,14 @@ class BaseOffset(_BaseOffset):
495514 return - self + other
496515
497516
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+
498525# ----------------------------------------------------------------------
499526# RelativeDelta Arithmetic
500527
0 commit comments