@@ -450,6 +450,7 @@ cdef class BaseOffset:
450450 def __add__ (self , other ):
451451 if not isinstance (self , BaseOffset):
452452 # cython semantics; this is __radd__
453+ # TODO(cython3): remove this, this moved to __radd__
453454 return other.__add__ (self )
454455
455456 elif util.is_array(other) and other.dtype == object :
@@ -460,19 +461,26 @@ cdef class BaseOffset:
460461 except ApplyTypeError:
461462 return NotImplemented
462463
464+ def __radd__ (self , other ):
465+ return self .__add__ (other)
466+
463467 def __sub__ (self , other ):
464468 if PyDateTime_Check(other):
465469 raise TypeError (' Cannot subtract datetime from offset.' )
466470 elif type (other) == type (self ):
467471 return type (self )(self .n - other.n, normalize = self .normalize,
468472 ** self .kwds)
469473 elif not isinstance (self , BaseOffset):
474+ # TODO(cython3): remove, this moved to __rsub__
470475 # cython semantics, this is __rsub__
471476 return (- other).__add__(self )
472477 else :
473478 # e.g. PeriodIndex
474479 return NotImplemented
475480
481+ def __rsub__ (self , other ):
482+ return (- self ).__add__(other)
483+
476484 def __call__ (self , other ):
477485 warnings.warn(
478486 " DateOffset.__call__ is deprecated and will be removed in a future "
@@ -499,10 +507,14 @@ cdef class BaseOffset:
499507 return type (self )(n = other * self .n, normalize = self .normalize,
500508 ** self .kwds)
501509 elif not isinstance (self , BaseOffset):
510+ # TODO(cython3): remove this, this moved to __rmul__
502511 # cython semantics, this is __rmul__
503512 return other.__mul__ (self )
504513 return NotImplemented
505514
515+ def __rmul__ (self , other ):
516+ return self .__mul__ (other)
517+
506518 def __neg__ (self ):
507519 # Note: we are deferring directly to __mul__ instead of __rmul__, as
508520 # that allows us to use methods that can go in a `cdef class`
@@ -887,6 +899,7 @@ cdef class Tick(SingleConstructorOffset):
887899
888900 def __mul__ (self , other ):
889901 if not isinstance (self , Tick):
902+ # TODO(cython3), remove this, this moved to __rmul__
890903 # cython semantics, this is __rmul__
891904 return other.__mul__ (self )
892905 if is_float_object(other):
@@ -900,6 +913,9 @@ cdef class Tick(SingleConstructorOffset):
900913 return new_self * other
901914 return BaseOffset.__mul__ (self , other)
902915
916+ def __rmul__ (self , other ):
917+ return self .__mul__ (other)
918+
903919 def __truediv__ (self , other ):
904920 if not isinstance (self , Tick):
905921 # cython semantics mean the args are sometimes swapped
@@ -908,9 +924,14 @@ cdef class Tick(SingleConstructorOffset):
908924 result = self .delta.__truediv__ (other)
909925 return _wrap_timedelta_result(result)
910926
927+ def __rtruediv__ (self , other ):
928+ result = self .delta.__rtruediv__ (other)
929+ return _wrap_timedelta_result(result)
930+
911931 def __add__ (self , other ):
912932 if not isinstance (self , Tick):
913933 # cython semantics; this is __radd__
934+ # TODO(cython3): remove this, this moved to __radd__
914935 return other.__add__ (self )
915936
916937 if isinstance (other, Tick):
@@ -928,6 +949,9 @@ cdef class Tick(SingleConstructorOffset):
928949 f" the add operation between {self} and {other} will overflow"
929950 ) from err
930951
952+ def __radd__ (self , other ):
953+ return self .__add__ (other)
954+
931955 def _apply (self , other ):
932956 # Timestamp can handle tz and nano sec, thus no need to use apply_wraps
933957 if isinstance (other, _Timestamp):
0 commit comments