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: Timedelta
description: Timedelta data type

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

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

```diff
@@            Coverage Diff             @@
##           master   #17433      +/-   ##
==========================================
- Coverage   91.16%   91.13%   -0.03%     
==========================================
  Files         163      163              
  Lines       49581    49603      +22     
==========================================
+ Hits        45199    45208       +9     
- Misses       4382     4395      +13
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `88.92% <84.37%> (-0.01%)` | :arrow_down: |
| #single | `40.24% <12.5%> (-0.08%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/17433?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/indexes/timedeltas.py](https://codecov.io/gh/pandas-dev/pandas/pull/17433?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy90aW1lZGVsdGFzLnB5) | `90.22% <84.37%> (-0.37%)` | :arrow_down: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/17433?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/17433?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.72% <0%> (-0.1%)` | :arrow_down: |

------

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

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

```diff
@@            Coverage Diff             @@
##           master   #17433      +/-   ##
==========================================
- Coverage   91.18%   91.13%   -0.06%     
==========================================
  Files         163      163              
  Lines       49545    49555      +10     
==========================================
- Hits        45179    45163      -16     
- Misses       4366     4392      +26
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `88.92% <80.88%> (-0.04%)` | :arrow_down: |
| #single | `40.26% <55.88%> (-0.02%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/17433?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/indexes/timedeltas.py](https://codecov.io/gh/pandas-dev/pandas/pull/17433?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy90aW1lZGVsdGFzLnB5) | `91.17% <ø> (+0.58%)` | :arrow_up: |
| [pandas/core/indexes/datetimes.py](https://codecov.io/gh/pandas-dev/pandas/pull/17433?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9kYXRldGltZXMucHk=) | `95.68% <ø> (+0.15%)` | :arrow_up: |
| [pandas/core/indexes/base.py](https://codecov.io/gh/pandas-dev/pandas/pull/17433?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9iYXNlLnB5) | `96.28% <100%> (ø)` | :arrow_up: |
| [pandas/core/indexes/period.py](https://codecov.io/gh/pandas-dev/pandas/pull/17433?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9wZXJpb2QucHk=) | `92.74% <100%> (ø)` | :arrow_up: |
| [pandas/core/indexes/datetimelike.py](https://codecov.io/gh/pandas-dev/pandas/pull/17433?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9kYXRldGltZWxpa2UucHk=) | `94.75% <80%> (-2.14%)` | :arrow_down: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/17433?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |
| [pandas/plotting/\_converter.py](https://codecov.io/gh/pandas-dev/pandas/pull/17433?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL19jb252ZXJ0ZXIucHk=) | `63.23% <0%> (-1.82%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/17433?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.77% <0%> (-0.1%)` | :arrow_down: |
| [pandas/core/categorical.py](https://codecov.io/gh/pandas-dev/pandas/pull/17433?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY2F0ZWdvcmljYWwucHk=) | `95.51% <0%> (-0.02%)` | :arrow_down: |
| [pandas/core/base.py](https://codecov.io/gh/pandas-dev/pandas/pull/17433?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYmFzZS5weQ==) | `96.01% <0%> (ø)` | :arrow_up: |
| ... and [6 more](https://codecov.io/gh/pandas-dev/pandas/pull/17433?src=pr&el=tree-more) | |

------

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

Thanks for the PR. It should have the similar logic as `DatetimeIndex` (may better to move to `datetimelike.py`).
https://github.com/pandas-dev/pandas/blob/master/pandas/core/indexes/datetimes.py#L1217

Also, `PeriodIndex` doesn't have the efficient logic ATM, but should be the same.
Hello @kirkhansen! Thanks for updating the PR.













Cheers ! There are no PEP8 issues in this Pull Request. :beers: 

##### Comment last updated on September 14, 2017 at 02:39 Hours UTC
@jreback most of the logic here is from a merge between the old timedeltas.py intersection, and the datetimes.py intersection. I assumed the logic in both of these were there for good reason. I'm fine with cleaning those types of things up per your merge request, but just know it was mostly copy paste, and I took the most restrictive version of each piece between the intersection functions I could find without fully understanding their reason for being there.
> @jreback most of the logic here is from a merge between the old timedeltas.py intersection, and the datetimes.py intersection. I assumed the logic in both of these were there for good reason. I'm fine with cleaning those types of things up per your merge request, but just know it was mostly copy paste, and I took the most restrictive version of each piece between the intersection functions I could find without fully understanding their reason for being there.

@kirkhansen yep I see that. When we refactor always like to clean up what is possible. For sure nice job on combining the disparate sub-class routines.
@kirkhansen some tests failures in `pandas/tests/io/test_pytables.py::TestHDFStore`, that I think are relevant Can you take a look (doing a release at the end of the week).
> some tests failures in pandas/tests/io/test_pytables.py::TestHDFStore, that I think are relevant Can you take a look (doing a release at the end of the week).

@TomAugspurger I haven't had much time for coding as of late. I haven't been able to reproduce this error locally (all the tests pass with my versions of things), but I'll try and dig into this tonight or tomorrow.
K. I just pulled your branch and wasn't able to reproduce either. I should have some time tomorrow to debug if you're busy.
@TomAugspurger I hate to say it, but if you're attempting to release at the end of the week, you may want to pick this up. I was unable to spend time on it yesterday and doubt I'll be able to look at this tonight.
can you rebase / update
closing as stale, but if you'd like to keep working, ping and we can reopen
@jreback I've been poking around at this again, getting stuff back up to date in hopes of resolving the build failure.
FWIW, the pytables tests pass now, but i get errors with `LooseVersion`. Those same errors show up in the master branch of my builds, so I'm not sure what its problem is since it's a copy of your master, and your master is passing.
FYI @kirkhansen you'll need to open a new PR. Github doesn't support closing a PR, bushing to the branch, and then reopening.