Fix #17965 datetime64 comparison
State: closed

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


Labels:
name: Datetime
description: Datetime data dtype
name: Dtype Conversions
description: Unexpected or buggy dtype conversions

Comments:
Python is inconsistent here:

```python
python                                                                                                                                                                                                                               Thu Nov  9 05:53:21 2017
Python 3.6.1 (default, Apr  4 2017, 09:40:21)
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.38)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> datetime.datetime(2017, 1, 1) == datetime.date(2017, 1, 1)
False
>>> datetime.datetime(2017, 1, 1) >= datetime.date(2017, 1, 1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can't compare datetime.datetime to datetime.date
```

Strange.... We should be a bit clearer on our policy if we're differing from Python. Are we saying that `datetime.datetimes` compare with a `datetime.date` by promoting the `date` to a datetime at midnight?
I don't think your comparison is correct - semantically the test is comparing two `date`s, not `datetimes`:
`datetime.date(2013,11,4) == datetime.date(2013,11,4)` is `True` - so we are not deviating from Python?
> Strange.... We should be a bit clearer on our policy if we're differing from Python. Are we saying that datetime.datetimes compare with a datetime.date by promoting the date to a datetime at midnight?

python is inconcistent here, ``datetime.date``  should just compare to ``datetime.datetime``, we just coerce everything to ``Timestamp`` in any event.
@watercrossing the comparison is a non-converted ``datetime.date`` vs a ``Timestamp``, which is what boxed versions of ``datetime64[ns]`` are. pls use the original issues exactly. 

testing against a column of ``datetime.date`` is possible as well, though this is more tricky to construct.
Reiterating suggestion to coerce datetime.date to Period with freq=D
> Reiterating suggestion to coerce datetime.date to Period with freq=D

not in this PR maybe at some point 
rebase as well
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/18188?src=pr&el=h1) Report
> Merging [#18188](https://codecov.io/gh/pandas-dev/pandas/pull/18188?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/9050e38bf8afea458a531b7af5b6b00b892f2b57?src=pr&el=desc) will **decrease** coverage by `0.04%`.
> The diff coverage is `n/a`.

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

```diff
@@            Coverage Diff             @@
##           master   #18188      +/-   ##
==========================================
- Coverage   91.42%   91.38%   -0.05%     
==========================================
  Files         163      163              
  Lines       50068    50068              
==========================================
- Hits        45777    45756      -21     
- Misses       4291     4312      +21
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `89.19% <ø> (-0.03%)` | :arrow_down: |
| #single | `40.35% <ø> (-0.06%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/18188?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/18188?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |
| [pandas/plotting/\_converter.py](https://codecov.io/gh/pandas-dev/pandas/pull/18188?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL19jb252ZXJ0ZXIucHk=) | `63.38% <0%> (-1.82%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/18188?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.8% <0%> (-0.1%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/18188?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/18188?src=pr&el=footer). Last update [9050e38...a56f7fe](https://codecov.io/gh/pandas-dev/pandas/pull/18188?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/18188?src=pr&el=h1) Report
> Merging [#18188](https://codecov.io/gh/pandas-dev/pandas/pull/18188?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/7f4c960c7d0c100e5df9f0a3bc68401fc4eace4d?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `n/a`.

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

```diff
@@            Coverage Diff             @@
##           master   #18188      +/-   ##
==========================================
+ Coverage   91.38%   91.38%   +<.01%     
==========================================
  Files         164      164              
  Lines       49884    49884              
==========================================
+ Hits        45584    45586       +2     
+ Misses       4300     4298       -2
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `89.19% <ø> (+0.02%)` | :arrow_up: |
| #single | `39.42% <ø> (-0.07%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/18188?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/18188?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/18188?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.8% <0%> (-0.1%)` | :arrow_down: |
| [pandas/core/indexes/datetimes.py](https://codecov.io/gh/pandas-dev/pandas/pull/18188?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9kYXRldGltZXMucHk=) | `95.38% <0%> (-0.1%)` | :arrow_down: |
| [pandas/plotting/\_converter.py](https://codecov.io/gh/pandas-dev/pandas/pull/18188?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL19jb252ZXJ0ZXIucHk=) | `65.25% <0%> (+1.81%)` | :arrow_up: |

------

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

ok ping on green.
@jreback: I have changed the whatsnew and rebased.
@watercrossing let us know if / when you see all the CI workers finish and we'll merge.
> @watercrossing let us know if / when you see all the CI workers finish and we'll merge.

@TomAugspurger optimist!
@TomAugspurger / @jreback: Ping!
thanks @watercrossing