implement truediv, rtruediv directly in TimedeltaArray; tests by jbrockmendel · Pull Request #23829 · pandas-dev/pandas (original) (raw)

Is the difference in behavior between TimedeltaIndex / timedelta64('NaT') and TimedeltaIndex / pd.NaT deliberate?

In [14]: rng = pd.timedelta_range(start='1D', periods=10, freq='D')

In [15]: rng / np.timedelta64('NaT') Out[15]: Float64Index([nan, nan, nan, nan, nan, nan, nan, nan, nan, nan], dtype='float64')

In [16]: rng / pd.NaT

TypeError Traceback (most recent call last) in ----> 1 rng / pd.NaT

~/sandbox/pandas-alt/pandas/core/indexes/timedeltas.py in truediv(self, other) 259 # TimedeltaArray defers, so we need to unwrap 260 oth = other._values --> 261 result = TimedeltaArray.truediv(self, oth) 262 return wrap_arithmetic_op(self, other, result) 263

~/sandbox/pandas-alt/pandas/core/arrays/timedeltas.py in truediv(self, other) 364 elif lib.is_scalar(other): 365 # assume it is numeric --> 366 result = self._data / other 367 freq = None 368 if self.freq is not None:

TypeError: ufunc true_divide cannot use operands with types dtype('<m8[ns]') and dtype('O')