BUG: Perform i8 conversion for datetimelike IntervalTree queries
State: closed

- [X] closes #20636
- [X] tests added / passed
- [X] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [X] whatsnew entry

I've seen a few complaints about this on StackOverflow, so wanted to get this into 0.24.0 before I try implementing larger changes like the new behavior specs and interval accessor.

Labels:
name: Bug
name: Datetime
description: Datetime data dtype
name: Indexing
description: Related to indexing on series/frames, not to indexes themselves
name: Interval
description: Interval data type

Comments:
Hello @jschendel! Thanks for submitting the PR.

 - There are no PEP8 issues in the file [`pandas/core/indexes/interval.py`](https://github.com/jschendel/pandas/blob/02f19f81f68e3c411f83d2341fa936a07f13a634/pandas/core/indexes/interval.py) !

 - There are no PEP8 issues in the file [`pandas/tests/indexes/interval/test_interval.py`](https://github.com/jschendel/pandas/blob/02f19f81f68e3c411f83d2341fa936a07f13a634/pandas/tests/indexes/interval/test_interval.py) !


Could you also add tests for `Period`s as well? I think they also need i8 conversion (though possibly less commonly used).
We currently do not allow an `IntervalIndex` to have `Period` endpoints, so I don't think tests are necessary:
```python
In [2]: pd.IntervalIndex.from_breaks(pd.period_range('2018Q1', freq='Q', periods=3))
---------------------------------------------------------------------------
ValueError: Period dtypes are not supported, use a PeriodIndex instead
```

Interestingly enough, it looks like an `Interval` _can_ have `Period` endpoints, which seems like a bug:
```python
In [3]: pd.Interval(pd.Period('2018Q1', freq='Q'), pd.Period('2018Q3', freq='Q'))
Out[3]: Interval(Period('2018Q1', 'Q-DEC'), Period('2018Q3', 'Q-DEC'), closed='right')
```
Gotcha. Are there plans for IntervalIndex to support Period? That might get tricky since Periods themselves are conceptually 1 label for an interval of time.
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/22988?src=pr&el=h1) Report
> Merging [#22988](https://codecov.io/gh/pandas-dev/pandas/pull/22988?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/c282e310809921a0dadd4446f23c9273c15da443?src=pr&el=desc) will **increase** coverage by `0.01%`.
> The diff coverage is `100%`.

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

```diff
@@            Coverage Diff             @@
##           master   #22988      +/-   ##
==========================================
+ Coverage   92.18%    92.2%   +0.01%     
==========================================
  Files         169      169              
  Lines       50823    50865      +42     
==========================================
+ Hits        46853    46898      +45     
+ Misses       3970     3967       -3
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.62% <100%> (+0.01%)` | :arrow_up: |
| #single | `42.33% <13.88%> (-0.04%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/22988?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/indexes/interval.py](https://codecov.io/gh/pandas-dev/pandas/pull/22988/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9pbnRlcnZhbC5weQ==) | `94.63% <100%> (+0.3%)` | :arrow_up: |
| [pandas/core/dtypes/dtypes.py](https://codecov.io/gh/pandas-dev/pandas/pull/22988/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZHR5cGVzL2R0eXBlcy5weQ==) | `95.56% <0%> (-0.3%)` | :arrow_down: |
| [pandas/core/reshape/merge.py](https://codecov.io/gh/pandas-dev/pandas/pull/22988/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvcmVzaGFwZS9tZXJnZS5weQ==) | `93.89% <0%> (-0.26%)` | :arrow_down: |
| [pandas/core/strings.py](https://codecov.io/gh/pandas-dev/pandas/pull/22988/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvc3RyaW5ncy5weQ==) | `98.63% <0%> (ø)` | :arrow_up: |
| [pandas/core/dtypes/base.py](https://codecov.io/gh/pandas-dev/pandas/pull/22988/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZHR5cGVzL2Jhc2UucHk=) | `100% <0%> (ø)` | :arrow_up: |
| [pandas/core/dtypes/cast.py](https://codecov.io/gh/pandas-dev/pandas/pull/22988/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZHR5cGVzL2Nhc3QucHk=) | `88.58% <0%> (ø)` | :arrow_up: |
| [pandas/core/series.py](https://codecov.io/gh/pandas-dev/pandas/pull/22988/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvc2VyaWVzLnB5) | `93.75% <0%> (ø)` | :arrow_up: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/22988/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.2% <0%> (ø)` | :arrow_up: |
| [pandas/core/dtypes/common.py](https://codecov.io/gh/pandas-dev/pandas/pull/22988/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZHR5cGVzL2NvbW1vbi5weQ==) | `95.03% <0%> (+0.01%)` | :arrow_up: |
| [pandas/core/arrays/datetimelike.py](https://codecov.io/gh/pandas-dev/pandas/pull/22988/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL2RhdGV0aW1lbGlrZS5weQ==) | `95.56% <0%> (+0.02%)` | :arrow_up: |
| ... and [5 more](https://codecov.io/gh/pandas-dev/pandas/pull/22988/diff?src=pr&el=tree-more) | |

------

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

> Are there plans for IntervalIndex to support Period? 

I'm not aware of any such plans.  I don't think the same type algorithms would apply; a `Period` is basically a special case of an `Interval`, so you'd essentially have intervals with interval endpoints (e.g. `Period('2018Q1')` is conceptually `Interval('2018-01-01', '2018-04-01', closed='left')` with some additional special properties.).  Haven't fully thought it through though.

There is an open issue to have `Period`/`PeriodIndex` inherit from `Interval`/`IntervalIndex` though, allowing one to use any of the interval methods on periods.  Not quite as straight forward as it might initially seem though, as we allow a `Period` to be outside the bounds of `Timestamp`, so just using `Timestamp` endpoints for the `Interval` representation wouldn't cut it.
@mroeschke as indicated above, a ``Period`` doesn't make sense as an element of an ``IntervalIndex``, though I don't think we actually preclude it, maybe we should. However implemented ``Period`` as a sub-class of ``Intevral`` and ``PeriodIndex`` as a sub-class of ``IntervalIndex``, *does* make sense (though may not be straightforward to actually do this).
thanks @jschendel