@@ -450,6 +450,7 @@ cdef class BaseOffset:
450
450
def __add__ (self , other ):
451
451
if not isinstance (self , BaseOffset):
452
452
# cython semantics; this is __radd__
453
+ # TODO(cython3): remove this, this moved to __radd__
453
454
return other.__add__ (self )
454
455
455
456
elif util.is_array(other) and other.dtype == object :
@@ -460,19 +461,26 @@ cdef class BaseOffset:
460
461
except ApplyTypeError:
461
462
return NotImplemented
462
463
464
+ def __radd__ (self , other ):
465
+ return self .__add__ (other)
466
+
463
467
def __sub__ (self , other ):
464
468
if PyDateTime_Check(other):
465
469
raise TypeError (' Cannot subtract datetime from offset.' )
466
470
elif type (other) == type (self ):
467
471
return type (self )(self .n - other.n, normalize = self .normalize,
468
472
** self .kwds)
469
473
elif not isinstance (self , BaseOffset):
474
+ # TODO(cython3): remove, this moved to __rsub__
470
475
# cython semantics, this is __rsub__
471
476
return (- other).__add__(self )
472
477
else :
473
478
# e.g. PeriodIndex
474
479
return NotImplemented
475
480
481
+ def __rsub__ (self , other ):
482
+ return (- self ).__add__(other)
483
+
476
484
def __call__ (self , other ):
477
485
warnings.warn(
478
486
" DateOffset.__call__ is deprecated and will be removed in a future "
@@ -499,10 +507,14 @@ cdef class BaseOffset:
499
507
return type (self )(n = other * self .n, normalize = self .normalize,
500
508
** self .kwds)
501
509
elif not isinstance (self , BaseOffset):
510
+ # TODO(cython3): remove this, this moved to __rmul__
502
511
# cython semantics, this is __rmul__
503
512
return other.__mul__ (self )
504
513
return NotImplemented
505
514
515
+ def __rmul__ (self , other ):
516
+ return self .__mul__ (other)
517
+
506
518
def __neg__ (self ):
507
519
# Note: we are deferring directly to __mul__ instead of __rmul__, as
508
520
# that allows us to use methods that can go in a `cdef class`
@@ -887,6 +899,7 @@ cdef class Tick(SingleConstructorOffset):
887
899
888
900
def __mul__ (self , other ):
889
901
if not isinstance (self , Tick):
902
+ # TODO(cython3), remove this, this moved to __rmul__
890
903
# cython semantics, this is __rmul__
891
904
return other.__mul__ (self )
892
905
if is_float_object(other):
@@ -900,6 +913,9 @@ cdef class Tick(SingleConstructorOffset):
900
913
return new_self * other
901
914
return BaseOffset.__mul__ (self , other)
902
915
916
+ def __rmul__ (self , other ):
917
+ return self .__mul__ (other)
918
+
903
919
def __truediv__ (self , other ):
904
920
if not isinstance (self , Tick):
905
921
# cython semantics mean the args are sometimes swapped
@@ -908,9 +924,14 @@ cdef class Tick(SingleConstructorOffset):
908
924
result = self .delta.__truediv__ (other)
909
925
return _wrap_timedelta_result(result)
910
926
927
+ def __rtruediv__ (self , other ):
928
+ result = self .delta.__rtruediv__ (other)
929
+ return _wrap_timedelta_result(result)
930
+
911
931
def __add__ (self , other ):
912
932
if not isinstance (self , Tick):
913
933
# cython semantics; this is __radd__
934
+ # TODO(cython3): remove this, this moved to __radd__
914
935
return other.__add__ (self )
915
936
916
937
if isinstance (other, Tick):
@@ -928,6 +949,9 @@ cdef class Tick(SingleConstructorOffset):
928
949
f" the add operation between {self} and {other} will overflow"
929
950
) from err
930
951
952
+ def __radd__ (self , other ):
953
+ return self .__add__ (other)
954
+
931
955
def _apply (self , other ):
932
956
# Timestamp can handle tz and nano sec, thus no need to use apply_wraps
933
957
if isinstance (other, _Timestamp):
0 commit comments