Masking and overflow checks for datetimeindex and timedeltaindex ops
State: closed

There are a bunch of new tests (not obvious what the appropriate place is for a WIP test matrix like this, pls advise).  The ones that will fail under master are `test_timedeltaindex_add_timestamp_nat_masking` and `test_datetimeindex_sub_timestamp_overflow`

Start filling out a test matrix of arithmetic ops.

- [x] closes #17991
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [ ] whatsnew entry


Labels:
name: Bug
name: Timedelta
description: Timedelta data type

Comments:
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/18020?src=pr&el=h1) Report
> Merging [#18020](https://codecov.io/gh/pandas-dev/pandas/pull/18020?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/3268f4e976a42065db3dcbc869f0c73adc0c7522?src=pr&el=desc) will **decrease** coverage by `0.01%`.
> The diff coverage is `100%`.

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

```diff
@@            Coverage Diff             @@
##           master   #18020      +/-   ##
==========================================
- Coverage   91.25%   91.23%   -0.02%     
==========================================
  Files         163      163              
  Lines       50123    50124       +1     
==========================================
- Hits        45741    45733       -8     
- Misses       4382     4391       +9
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `89.05% <100%> (ø)` | :arrow_up: |
| #single | `40.32% <20%> (-0.06%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/18020?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/indexes/timedeltas.py](https://codecov.io/gh/pandas-dev/pandas/pull/18020?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy90aW1lZGVsdGFzLnB5) | `91.19% <100%> (ø)` | :arrow_up: |
| [pandas/core/indexes/datetimelike.py](https://codecov.io/gh/pandas-dev/pandas/pull/18020?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9kYXRldGltZWxpa2UucHk=) | `97.1% <100%> (ø)` | :arrow_up: |
| [pandas/core/indexes/datetimes.py](https://codecov.io/gh/pandas-dev/pandas/pull/18020?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9kYXRldGltZXMucHk=) | `95.51% <100%> (ø)` | :arrow_up: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/18020?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/18020?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.75% <0%> (-0.1%)` | :arrow_down: |

------

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

OK, just removed the new file, took the two tests that currently fail on master and moved them into existing datetime and timedelta test files.
Does this also fix https://github.com/pandas-dev/pandas/issues/7996 ?
> Does this also fix #7996 ?

No, but it does fix a related bug that probably belongs in the same issue

```
In [3]: s = pd.Series(pd.date_range('20130101',periods=3))
In [4]: dti = pd.DatetimeIndex(s)

In [5]: s-np.datetime64('2013-01-01')
Out[5]: 
0   15705 days 23:59:59.999984
1   15706 days 23:59:59.999984
2   15707 days 23:59:59.999984
dtype: timedelta64[ns]

In [6]: dti - np.datetime64('2013-01-01')
Out[6]: DatetimeIndex(['1970-01-01', '1970-01-02', '1970-01-03'], dtype='datetime64[ns]', freq=None)
```
Rebased and pushed; hoping that magically fixes the CI errors
AFAICT the test failures here were caused because of fragility in `test_NaT_methods` and `TestTimestamp.test_to_datetime_depr`.  Specifically, a test that this PR added (until moments ago) called `ts.to_datetime()` instead of `ts.to_pydatetime()`.  This triggered a `FutureWarning`, which resulted in `FutureWarning` not being called in the tests that specifically check for it.

I think the immediate issue is now fixed, but ideally `test_to_datetime_depr` and `test_NaT_methods` would be isolated enough not to depend on test ordering.
Where did we land on this?  My preference is to get this bug-fix in and worry about the rest in #18049+followups.
needs a rebase
Just rebased.  The two new tests are unchanged, just moved to the appropriate locations in test_arithmetic.
looks fine, tiny doc change. ping on green.
ping on green.
ping
thanks!