implement truediv, rtruediv directly in TimedeltaArray; tests
State: closed

Follow-up to #23642, implements `__rdiv__` in TimedeltaArray, plus missing tests.

After this will be a PR that does the same for floordiv+rfloordiv.

- [x] closes #22631
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry

Fixes:
`tdi / np.timedelta64('NaT')`
` tdi / tdi` (#22631)
`tdi / object_dtyped`
`object_dtyped / tdi`

Labels:
name: Numeric Operations
description: Arithmetic, Comparison, and Logical operations
name: Timedelta
description: Timedelta data type

Comments:
Hello @jbrockmendel! Thanks for updating the PR.

 - There are no PEP8 issues in the file [`pandas/core/arrays/timedeltas.py`](https://github.com/jbrockmendel/pandas/blob/d72bf9053803d1a9239682fd47b4a0ca7aaa0c06/pandas/core/arrays/timedeltas.py) !

 - There are no PEP8 issues in the file [`pandas/core/indexes/base.py`](https://github.com/jbrockmendel/pandas/blob/d72bf9053803d1a9239682fd47b4a0ca7aaa0c06/pandas/core/indexes/base.py) !

 - There are no PEP8 issues in the file [`pandas/core/indexes/timedeltas.py`](https://github.com/jbrockmendel/pandas/blob/d72bf9053803d1a9239682fd47b4a0ca7aaa0c06/pandas/core/indexes/timedeltas.py) !

 - There are no PEP8 issues in the file [`pandas/tests/arithmetic/test_timedelta64.py`](https://github.com/jbrockmendel/pandas/blob/d72bf9053803d1a9239682fd47b4a0ca7aaa0c06/pandas/tests/arithmetic/test_timedelta64.py) !



##### Comment last updated on November 29, 2018 at 02:49 Hours UTC
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/23829?src=pr&el=h1) Report
> Merging [#23829](https://codecov.io/gh/pandas-dev/pandas/pull/23829?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/982c169a286d436481364d2a6c27b355a83472b5?src=pr&el=desc) will **decrease** coverage by `<.01%`.
> The diff coverage is `92.1%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/23829/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/23829?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #23829      +/-   ##
==========================================
- Coverage   92.31%   92.31%   -0.01%     
==========================================
  Files         161      161              
  Lines       51513    51578      +65     
==========================================
+ Hits        47554    47613      +59     
- Misses       3959     3965       +6
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.71% <92.1%> (ø)` | :arrow_up: |
| #single | `42.37% <13.15%> (-0.05%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/23829?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/indexes/base.py](https://codecov.io/gh/pandas-dev/pandas/pull/23829/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9iYXNlLnB5) | `96.32% <66.66%> (-0.17%)` | :arrow_down: |
| [pandas/core/indexes/timedeltas.py](https://codecov.io/gh/pandas-dev/pandas/pull/23829/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy90aW1lZGVsdGFzLnB5) | `89.6% <86.66%> (+0.07%)` | :arrow_up: |
| [pandas/core/arrays/timedeltas.py](https://codecov.io/gh/pandas-dev/pandas/pull/23829/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL3RpbWVkZWx0YXMucHk=) | `95.95% <96.36%> (-0.31%)` | :arrow_down: |
| [pandas/io/formats/printing.py](https://codecov.io/gh/pandas-dev/pandas/pull/23829/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvcHJpbnRpbmcucHk=) | `93.61% <0%> (+0.53%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/23829?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/23829?src=pr&el=footer). Last update [982c169...d72bf90](https://codecov.io/gh/pandas-dev/pandas/pull/23829?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

Next round implementing floordiv, mod, divmod, and reversed ops is almost ready.  Any preference between follow-up vs adding to this PR?
> Any preference between follow-up vs adding to this PR?

How many more things do you need to follow-up on?  And how straightforward are they to handle?  Probably would lean towards merging this and follow-up later, but not sure whether some of the remaining comments are blockers...
I think all comments have been addressed
Travis fail is unrelated flake8-rst problem
ping
thanks!
Is the difference in behavior between `TimedeltaIndex / timedelta64('NaT')` and `TimedeltaIndex / pd.NaT` deliberate?


```python
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)
<ipython-input-16-0bf699fa1965> in <module>
----> 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')

```
> Is the difference in behavior between TimedeltaIndex / timedelta64('NaT') and TimedeltaIndex / pd.NaT deliberate?

Yes.  timedelta64("NaT") is unambiguously timedelta-like, whereas pd.NaT is both datetime-like and timedelta-like (and defaults to datetime-like).
Thanks for the clarification.

On Tue, Dec 11, 2018 at 11:53 AM jbrockmendel <notifications@github.com>
wrote:

> Is the difference in behavior between TimedeltaIndex / timedelta64('NaT')
> and TimedeltaIndex / pd.NaT deliberate?
>
> Yes. timedelta64("NaT") is unambiguously timedelta-like, whereas pd.NaT is
> both datetime-like and timedelta-like (and defaults to datetime-like).
>
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub
> <https://github.com/pandas-dev/pandas/pull/23829#issuecomment-446297382>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/ABQHIir-WB_mF_gczMVbnt2o4SsZUH-oks5u3_ERgaJpZM4YsTAg>
> .
>