Warn on ndarray[int] // timedelta
State: closed

Closes #19761.

```python
In [2]: pd.DatetimeIndex(['1931', '1970', '2017']).view('i8') // pd.Timedelta(1, unit='s')
pandas-dev/bin/ipython:1: FutureWarning: Floor division between integer array and Timedelta is
deprecated. Use 'array // timedelta.value' instead.

Out[2]: array([-1230768000,           0,  1483228800])
```

Long-term, we'll recommend using `to_epoch` for the case where people are doing this to do conversion to unix epoch. But https://github.com/pandas-dev/pandas/issues/14772 has a few design issues that will take some time to discuss. I think we should just recommend `.value` for now.

Labels:
name: Numeric Operations
description: Arithmetic, Comparison, and Logical operations
name: Timedelta
description: Timedelta data type
name: Deprecate
description: Functionality to remove in pandas

Comments:
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/21036?src=pr&el=h1) Report
> Merging [#21036](https://codecov.io/gh/pandas-dev/pandas/pull/21036?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/a5c02d5c4225a90cda8ed7f328306bd9754d0f93?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `n/a`.

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

```diff
@@           Coverage Diff           @@
##           master   #21036   +/-   ##
=======================================
  Coverage   91.82%   91.82%           
=======================================
  Files         153      153           
  Lines       49502    49502           
=======================================
  Hits        45457    45457           
  Misses       4045     4045
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.22% <ø> (ø)` | :arrow_up: |
| #single | `41.88% <ø> (ø)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/21036?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/io/parsers.py](https://codecov.io/gh/pandas-dev/pandas/pull/21036/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3BhcnNlcnMucHk=) | `95.46% <0%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/21036?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/21036?src=pr&el=footer). Last update [a5c02d5...9fa7583](https://codecov.io/gh/pandas-dev/pandas/pull/21036?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

thanks!
The maybe tricky thing there is that not all ndarray[int] // timedelta
operations are necessarily for epoch conversions. They would be the
majority though...

On Tue, May 15, 2018 at 8:06 AM, Joris Van den Bossche <
notifications@github.com> wrote:

> *@jorisvandenbossche* commented on this pull request.
> ------------------------------
>
> In pandas/_libs/tslibs/timedeltas.pyx
> <https://github.com/pandas-dev/pandas/pull/21036#discussion_r188278343>:
>
> > @@ -1188,6 +1190,15 @@ class Timedelta(_Timedelta):
>              if other.dtype.kind == 'm':
>                  # also timedelta-like
>                  return _broadcast_floordiv_td64(self.value, other, _rfloordiv)
> +            elif other.dtype.kind == 'i':
> +                # Backwards compatibility
> +                # GH-19761
> +                msg = textwrap.dedent("""\
> +                Floor division between integer array and Timedelta is
> +                deprecated. Use 'array // timedelta.value' instead.
>
> Since you updated the example in the docs, maybe we should reflect this as
> well in the deprecation message?
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/pandas-dev/pandas/pull/21036#pullrequestreview-120222388>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/ABQHIpnZJXikD1ccI2FzlnxTxW-tMSEtks5tytLSgaJpZM4T-UP4>
> .
>

I don't know who else would be doing that :-) But it's true that it's not necessarily the case. I can do a PR to add that explanation in addition to the current one if you like.
That'd be great. Tracking down some dask issues to verify we don't have any
other regressions right now, so we've got some time.

On Tue, May 15, 2018 at 9:31 AM, Joris Van den Bossche <
notifications@github.com> wrote:

> I don't know who else would be doing that :-) But it's true that it's not
> necessarily the case. I can do a PR to add that explanation in addition to
> the current one if you like.
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/pandas-dev/pandas/pull/21036#issuecomment-389188581>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/ABQHIi7XS2ASNaCSIUpCRLQ6WHn_nsa-ks5tyubdgaJpZM4T-UP4>
> .
>

Should users also get warned on timedelta // int, which happens with timedelta % int too? Maybe the warning should pop up everytime a number is implicitly converted to a timestamp, as the current behavior does not seem very consistent with addition for example.