[ENH] Move intersection functions for DatetimeIndex and TimedeltaIndex to Datetimelike and added 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.

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

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

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

```diff
@@            Coverage Diff             @@
##           master   #25121      +/-   ##
==========================================
+ Coverage   92.37%   92.38%   +<.01%     
==========================================
  Files         166      166              
  Lines       52415    52395      -20     
==========================================
- Hits        48418    48404      -14     
+ Misses       3997     3991       -6
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.8% <92.68%> (ø)` | :arrow_up: |
| #single | `42.89% <36.58%> (+0.02%)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/25121?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/indexes/datetimes.py](https://codecov.io/gh/pandas-dev/pandas/pull/25121/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9kYXRldGltZXMucHk=) | `96.73% <ø> (+0.45%)` | :arrow_up: |
| [pandas/core/indexes/timedeltas.py](https://codecov.io/gh/pandas-dev/pandas/pull/25121/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy90aW1lZGVsdGFzLnB5) | `90.99% <ø> (+0.76%)` | :arrow_up: |
| [pandas/core/indexes/period.py](https://codecov.io/gh/pandas-dev/pandas/pull/25121/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9wZXJpb2QucHk=) | `92.1% <100%> (+0.03%)` | :arrow_up: |
| [pandas/core/indexes/datetimelike.py](https://codecov.io/gh/pandas-dev/pandas/pull/25121/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9kYXRldGltZWxpa2UucHk=) | `97.88% <92.3%> (-0.65%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/25121?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/25121?src=pr&el=footer). Last update [a814ea4...0540312](https://codecov.io/gh/pandas-dev/pandas/pull/25121?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/25121?src=pr&el=h1) Report
> Merging [#25121](https://codecov.io/gh/pandas-dev/pandas/pull/25121?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/a814ea480e416f14550d9dd9e16c19d69619663f?src=pr&el=desc) will **decrease** coverage by `0.2%`.
> The diff coverage is `93.75%`.

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

```diff
@@            Coverage Diff             @@
##           master   #25121      +/-   ##
==========================================
- Coverage   92.37%   92.16%   -0.21%     
==========================================
  Files         166      166              
  Lines       52415    52279     -136     
==========================================
- Hits        48418    48184     -234     
- Misses       3997     4095      +98
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.63% <93.75%> (-0.17%)` | :arrow_down: |
| #single | `42.29% <43.75%> (-0.58%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/25121?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/indexes/period.py](https://codecov.io/gh/pandas-dev/pandas/pull/25121/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/25121/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9kYXRldGltZXMucHk=) | `96.74% <100%> (+0.46%)` | :arrow_up: |
| [pandas/core/indexes/timedeltas.py](https://codecov.io/gh/pandas-dev/pandas/pull/25121/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy90aW1lZGVsdGFzLnB5) | `91.04% <100%> (+0.82%)` | :arrow_up: |
| [pandas/core/indexes/datetimelike.py](https://codecov.io/gh/pandas-dev/pandas/pull/25121/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9kYXRldGltZWxpa2UucHk=) | `97.88% <92.3%> (-0.65%)` | :arrow_down: |
| [pandas/core/panel.py](https://codecov.io/gh/pandas-dev/pandas/pull/25121/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvcGFuZWwucHk=) | `93.87% <0%> (-4.05%)` | :arrow_down: |
| [pandas/core/groupby/ops.py](https://codecov.io/gh/pandas-dev/pandas/pull/25121/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ3JvdXBieS9vcHMucHk=) | `94.15% <0%> (-2.58%)` | :arrow_down: |
| [pandas/io/pytables.py](https://codecov.io/gh/pandas-dev/pandas/pull/25121/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3B5dGFibGVzLnB5) | `90.42% <0%> (-1.89%)` | :arrow_down: |
| [pandas/core/computation/pytables.py](https://codecov.io/gh/pandas-dev/pandas/pull/25121/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY29tcHV0YXRpb24vcHl0YWJsZXMucHk=) | `90.54% <0%> (-1.81%)` | :arrow_down: |
| [pandas/core/internals/managers.py](https://codecov.io/gh/pandas-dev/pandas/pull/25121/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW50ZXJuYWxzL21hbmFnZXJzLnB5) | `94.83% <0%> (-1.24%)` | :arrow_down: |
| [pandas/core/computation/expr.py](https://codecov.io/gh/pandas-dev/pandas/pull/25121/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY29tcHV0YXRpb24vZXhwci5weQ==) | `88.17% <0%> (-0.52%)` | :arrow_down: |
| ... and [26 more](https://codecov.io/gh/pandas-dev/pandas/pull/25121/diff?src=pr&el=tree-more) | |

------

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

@jreback and @jorisvandenbossche Thanks for the feedback, I think that all should be addressed, locally it looks find on my side. I hope the `super` syntax is correct and please let me know if the `parametrize` line breaks are offending anyones aesthetic feelings :) 
would love to have this. pls ping if you are interested in continuing. would need to rebase on master.
@fdroessler let me know if you don't have time to finish this at the moment and I can pick it up.
@reidy-p No I am happy to finish it, as mentioned in the comments above I thought I addressed all points from @jreback but maybe I did not mark them appropriately or he can let me know what is missing? I'll rebase and push it.
@fdroessler can you open a new PR ? (once you push to a branch after the PR has been closed, github does not let you reopen the PR ...)
@jorisvandenbossche @jreback I submitted a new PR #25913 let me know if there are any missing issues you want me to resolve, happy to work on it.