[ENH] Move intersection functions for DatetimeIndex and TimedeltaIndex to Datetimelike and added new tests
State: closed

- [x] closes #24966
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry

Because DatetimeIndex and TimedeltaIndex intersections are similar, I have moved the intersection function of both classes up into Datetimelike after discussions with @reidy-p @jorisvandenbossche. At the same time for PeriodIndex I have used Index.intersection instead. Additionally I have added some tests to TimedeltaIndex recycling some tests from DatetimeIndex.

Re-open from #25121

Labels:
name: Timedelta
description: Timedelta data type
name: Clean

Comments:
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/25913?src=pr&el=h1) Report
> Merging [#25913](https://codecov.io/gh/pandas-dev/pandas/pull/25913?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/31b4019ef290bc55855e079b2b7dddcc39a16fc4?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `93.75%`.

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

```diff
@@            Coverage Diff             @@
##           master   #25913      +/-   ##
==========================================
+ Coverage   91.56%   91.56%   +<.01%     
==========================================
  Files         175      175              
  Lines       52775    52760      -15     
==========================================
- Hits        48324    48312      -12     
+ Misses       4451     4448       -3
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.13% <93.75%> (ø)` | :arrow_up: |
| #single | `41.84% <43.75%> (-0.06%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/25913?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/indexes/period.py](https://codecov.io/gh/pandas-dev/pandas/pull/25913/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9wZXJpb2QucHk=) | `92.12% <100%> (+0.05%)` | :arrow_up: |
| [pandas/core/indexes/datetimes.py](https://codecov.io/gh/pandas-dev/pandas/pull/25913/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9kYXRldGltZXMucHk=) | `96.86% <100%> (+0.45%)` | :arrow_up: |
| [pandas/core/indexes/timedeltas.py](https://codecov.io/gh/pandas-dev/pandas/pull/25913/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy90aW1lZGVsdGFzLnB5) | `91.09% <100%> (+0.82%)` | :arrow_up: |
| [pandas/core/indexes/datetimelike.py](https://codecov.io/gh/pandas-dev/pandas/pull/25913/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9kYXRldGltZWxpa2UucHk=) | `97.89% <92.3%> (-0.64%)` | :arrow_down: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/25913/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `75% <0%> (-12.5%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/25913/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `96.79% <0%> (-0.12%)` | :arrow_down: |
| [pandas/util/testing.py](https://codecov.io/gh/pandas-dev/pandas/pull/25913/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvdGVzdGluZy5weQ==) | `90.56% <0%> (+0.1%)` | :arrow_up: |

------

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

# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/25913?src=pr&el=h1) Report
> Merging [#25913](https://codecov.io/gh/pandas-dev/pandas/pull/25913?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/9feb3ad92cc0397a04b665803a49299ee7aa1037?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `95.45%`.

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

```diff
@@            Coverage Diff             @@
##           master   #25913      +/-   ##
==========================================
+ Coverage   91.97%   91.97%   +<.01%     
==========================================
  Files         175      175              
  Lines       52368    52349      -19     
==========================================
- Hits        48164    48148      -16     
+ Misses       4204     4201       -3
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.53% <95.45%> (ø)` | :arrow_up: |
| #single | `40.72% <52.27%> (-0.12%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/25913?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/indexes/period.py](https://codecov.io/gh/pandas-dev/pandas/pull/25913/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9wZXJpb2QucHk=) | `92.1% <100%> (+0.05%)` | :arrow_up: |
| [pandas/core/indexes/datetimes.py](https://codecov.io/gh/pandas-dev/pandas/pull/25913/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9kYXRldGltZXMucHk=) | `96.85% <100%> (+0.45%)` | :arrow_up: |
| [pandas/core/indexes/timedeltas.py](https://codecov.io/gh/pandas-dev/pandas/pull/25913/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy90aW1lZGVsdGFzLnB5) | `91.59% <100%> (+0.86%)` | :arrow_up: |
| [pandas/core/indexes/datetimelike.py](https://codecov.io/gh/pandas-dev/pandas/pull/25913/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9kYXRldGltZWxpa2UucHk=) | `98.13% <94.28%> (-0.4%)` | :arrow_down: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/25913/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `78.94% <0%> (-10.53%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/25913/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `96.9% <0%> (-0.12%)` | :arrow_down: |

------

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

@gfyoung not sure if I should mark the comments as resolved or if you do it once you had a look at it. Please let me know what the general practice is on those so I know for the future.
@jreback Is there anything else? Do you want me to create a new issue re restructuring the tests?
@TomAugspurger if you could have a look
Probably won’t be able to for a while. Don’t hold this up because of me. 

> On Apr 12, 2019, at 06:39, Jeff Reback <notifications@github.com> wrote:
> 
> @TomAugspurger if you could have a look
> 
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub, or mute the thread.

@fdroessler can you merge master and will have a look.
@jreback sure, done
can you merge master
Done @jreback 
thanks @fdroessler very nice!