BUG: TimedeltaIndex.intersection
State: closed

- [ ] closes #17391
- [ ] tests added / passed
- [ ] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [ ] whatsnew entry


Labels:
name: Bug
name: Reshaping
description: Concat, Merge/Join, Stack/Unstack, Explode
name: Timedelta
description: Timedelta data type

Comments:
Having come back at this, I'm struggling with how to deal with all the edge cases that need to be accounted for before trying to apply this quick method of intersecting, and this is making me question whether or not to even include it. 
The quick method cannot allow any 'gaps' between values, unless both indexes have the same gaps, and having to check for that before intersecting seems a lot harder than just using `Index.intersection`, unless that method is worse than something we can write to check if if values are contiguous based on the frequency passed in or something.

I'm having a hard time describing it clearly, but hopefully this is making sense. If not, I can commit my broken code so you all can see what I'm talking about.
A possibility to at least solve the bug would be to fall back to the `Index.intersection` implementation for the cases where monotonicity does not match?

Basically similar like `DatetimeIndex.intersection` also falls back to it when eg freq does not match:

https://github.com/pandas-dev/pandas/blob/59cfd8cf826c79f8633c3a47aab53cafa3927bac/pandas/core/indexes/datetimes.py#L1006-L1015

Will not be the most performant option, but at least could fix the bug
@jorisvandenbossche I thought I had been doing that, but it seems my check was backwards for that case :/. Correcting that appears to solve the issues. Thanks!
Hello @kirkhansen! Thanks for updating the PR.

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

 - There are no PEP8 issues in the file [`pandas/core/indexes/datetimelike.py`](https://github.com/kirkhansen/pandas/blob/4aac7e824ea4b0200e39df13921cd75a28e071a8/pandas/core/indexes/datetimelike.py) !

 - There are no PEP8 issues in the file [`pandas/core/indexes/datetimes.py`](https://github.com/kirkhansen/pandas/blob/4aac7e824ea4b0200e39df13921cd75a28e071a8/pandas/core/indexes/datetimes.py) !

 - There are no PEP8 issues in the file [`pandas/core/indexes/period.py`](https://github.com/kirkhansen/pandas/blob/4aac7e824ea4b0200e39df13921cd75a28e071a8/pandas/core/indexes/period.py) !

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

 - There are no PEP8 issues in the file [`pandas/tests/indexes/datetimes/test_setops.py`](https://github.com/kirkhansen/pandas/blob/4aac7e824ea4b0200e39df13921cd75a28e071a8/pandas/tests/indexes/datetimes/test_setops.py) !

 - There are no PEP8 issues in the file [`pandas/tests/indexes/timedeltas/test_setops.py`](https://github.com/kirkhansen/pandas/blob/4aac7e824ea4b0200e39df13921cd75a28e071a8/pandas/tests/indexes/timedeltas/test_setops.py) !

 - There are no PEP8 issues in the file [`pandas/tests/io/test_pytables.py`](https://github.com/kirkhansen/pandas/blob/4aac7e824ea4b0200e39df13921cd75a28e071a8/pandas/tests/io/test_pytables.py) !

 - There are no PEP8 issues in the file [`pandas/tseries/offsets.py`](https://github.com/kirkhansen/pandas/blob/4aac7e824ea4b0200e39df13921cd75a28e071a8/pandas/tseries/offsets.py) !



##### Comment last updated on December 12, 2018 at 21:29 Hours UTC
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/22114?src=pr&el=h1) Report
> Merging [#22114](https://codecov.io/gh/pandas-dev/pandas/pull/22114?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/9bc42f9d296cf717533051ee76130e72ea9ce557?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `86.79%`.

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

```diff
@@            Coverage Diff             @@
##           master   #22114      +/-   ##
==========================================
+ Coverage   92.21%   92.22%   +<.01%     
==========================================
  Files         162      162              
  Lines       51768    51761       -7     
==========================================
- Hits        47739    47734       -5     
+ Misses       4029     4027       -2
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.62% <86.79%> (ø)` | :arrow_up: |
| #single | `43.14% <47.16%> (+0.14%)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/22114?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/indexes/datetimes.py](https://codecov.io/gh/pandas-dev/pandas/pull/22114/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9kYXRldGltZXMucHk=) | `96.8% <ø> (+0.46%)` | :arrow_up: |
| [pandas/core/indexes/period.py](https://codecov.io/gh/pandas-dev/pandas/pull/22114/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9wZXJpb2QucHk=) | `93.06% <100%> (ø)` | :arrow_up: |
| [pandas/tseries/offsets.py](https://codecov.io/gh/pandas-dev/pandas/pull/22114/diff?src=pr&el=tree#diff-cGFuZGFzL3RzZXJpZXMvb2Zmc2V0cy5weQ==) | `96.86% <100%> (+0.01%)` | :arrow_up: |
| [pandas/core/indexes/base.py](https://codecov.io/gh/pandas-dev/pandas/pull/22114/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9iYXNlLnB5) | `96.27% <100%> (ø)` | :arrow_up: |
| [pandas/core/indexes/timedeltas.py](https://codecov.io/gh/pandas-dev/pandas/pull/22114/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy90aW1lZGVsdGFzLnB5) | `90.69% <33.33%> (+0.26%)` | :arrow_up: |
| [pandas/core/indexes/datetimelike.py](https://codecov.io/gh/pandas-dev/pandas/pull/22114/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9kYXRldGltZWxpa2UucHk=) | `96.24% <87.5%> (-1.06%)` | :arrow_down: |

------

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

if you can merge master
You'll need to run `isort` on this file:

```
2018-12-12T21:36:13.4930067Z ERROR: /home/vsts/work/1/s/pandas/core/indexes/datetimelike.py Imports are incorrectly sorted.
```
Closing as stale ping if you'd like to continue