@@ -471,9 +471,12 @@ def _binary_op_method_timedeltalike(op, name):
471
471
# define a binary operation that only works if the other argument is
472
472
# timedelta like or an array of timedeltalike
473
473
def f (self , other ):
474
- if hasattr (other, ' delta' ) and not PyDelta_Check(other):
475
- # offsets.Tick
476
- return op(self , other.delta)
474
+ if hasattr (other, ' _typ' ):
475
+ # Series, DataFrame, ...
476
+ if other._typ == ' dateoffset' and hasattr (other, ' delta' ):
477
+ # Tick offset
478
+ return op(self , other.delta)
479
+ return NotImplemented
477
480
478
481
elif other is NaT:
479
482
return NaT
@@ -1052,7 +1055,14 @@ class Timedelta(_Timedelta):
1052
1055
__rsub__ = _binary_op_method_timedeltalike(lambda x , y : y - x, ' __rsub__' )
1053
1056
1054
1057
def __mul__ (self , other ):
1055
- if hasattr (other, ' dtype' ):
1058
+ if hasattr (other, ' _typ' ):
1059
+ # Series, DataFrame, ...
1060
+ if other._typ == ' dateoffset' and hasattr (other, ' delta' ):
1061
+ # Tick offset; this op will raise TypeError
1062
+ return other.delta * self
1063
+ return NotImplemented
1064
+
1065
+ elif hasattr (other, ' dtype' ):
1056
1066
# ndarray-like
1057
1067
return other * self .to_timedelta64()
1058
1068
@@ -1068,7 +1078,18 @@ class Timedelta(_Timedelta):
1068
1078
__rmul__ = __mul__
1069
1079
1070
1080
def __truediv__ (self , other ):
1071
- if hasattr (other, ' dtype' ):
1081
+ if hasattr (other, ' _typ' ):
1082
+ # Series, DataFrame, ...
1083
+ if other._typ == ' dateoffset' and hasattr (other, ' delta' ):
1084
+ # Tick offset
1085
+ return self / other.delta
1086
+ return NotImplemented
1087
+
1088
+ elif is_timedelta64_object(other):
1089
+ # convert to Timedelta below
1090
+ pass
1091
+
1092
+ elif hasattr (other, ' dtype' ):
1072
1093
return self .to_timedelta64() / other
1073
1094
1074
1095
elif is_integer_object(other) or is_float_object(other):
@@ -1084,7 +1105,18 @@ class Timedelta(_Timedelta):
1084
1105
return self .value / float (other.value)
1085
1106
1086
1107
def __rtruediv__ (self , other ):
1087
- if hasattr (other, ' dtype' ):
1108
+ if hasattr (other, ' _typ' ):
1109
+ # Series, DataFrame, ...
1110
+ if other._typ == ' dateoffset' and hasattr (other, ' delta' ):
1111
+ # Tick offset
1112
+ return other.delta / self
1113
+ return NotImplemented
1114
+
1115
+ elif is_timedelta64_object(other):
1116
+ # convert to Timedelta below
1117
+ pass
1118
+
1119
+ elif hasattr (other, ' dtype' ):
1088
1120
return other / self .to_timedelta64()
1089
1121
1090
1122
elif not _validate_ops_compat(other):
@@ -1160,9 +1192,10 @@ class Timedelta(_Timedelta):
1160
1192
' {op}' .format(dtype = other.dtype,
1161
1193
op = ' __floordiv__' ))
1162
1194
1163
- if is_float_object(other) and util._checknull(other):
1195
+ elif is_float_object(other) and util._checknull(other):
1164
1196
# i.e. np.nan
1165
1197
return NotImplemented
1198
+
1166
1199
elif not _validate_ops_compat(other):
1167
1200
return NotImplemented
1168
1201
0 commit comments