core: try coerce result back to DatetimeBlock
State: closed

- [x] closes #21610 #8554 #12437
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry
---
Hang up until `Block.eval` reformed.

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

Comments:
@jbrockmendel . Should this work with tz-aware date times as well?
> Should this work with tz-aware date times as well?

Yes.

If there's any way at all to do this without poking into core.internals, that would be preferred.  The Series version of this works correctly right?  This should be doing something like operating column-wise to dispatch to the Series implementation (which itself dispatches to the DatetimeIndex implementation).

Can you include tests for subtraction while you're at it?
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/22008?src=pr&el=h1) Report
> Merging [#22008](https://codecov.io/gh/pandas-dev/pandas/pull/22008?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/0828c25913b5862d70322471a6ee4fa11d8f890d?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `100%`.

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

```diff
@@            Coverage Diff             @@
##           master   #22008      +/-   ##
==========================================
+ Coverage   91.99%   91.99%   +<.01%     
==========================================
  Files         167      167              
  Lines       50578    50588      +10     
==========================================
+ Hits        46530    46540      +10     
  Misses       4048     4048
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.4% <100%> (ø)` | :arrow_up: |
| #single | `42.17% <18.18%> (-0.01%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/22008?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/internals/\_\_init\_\_.py](https://codecov.io/gh/pandas-dev/pandas/pull/22008/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW50ZXJuYWxzL19faW5pdF9fLnB5) | `95.51% <100%> (+0.01%)` | :arrow_up: |

------

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

v2.0, override `DatetimeBlock.eval`.

Below test fails, but not a regression. Will look deeper later.
```python
    def test_timestamp_df_sub_timestamp(self):
        expected = pd.DataFrame([pd.Timedelta('365d')])
        result = pd.DataFrame([pd.Timestamp('2018')]) - pd.Timestamp('2017')
        tm.assert_frame_equal(expected, result)
```
docs said returning a new `block`, but indeed it returns a singleton `list`.

https://github.com/pandas-dev/pandas/blob/37c74585e82772ad2e8e4402346c66462b0621b3/pandas/core/internals/__init__.py#L1333-L1336
https://github.com/pandas-dev/pandas/blob/37c74585e82772ad2e8e4402346c66462b0621b3/pandas/core/internals/__init__.py#L1455-L1457
Hang up until `Block.eval` reformed. This will also close #8554 #12437.
Two of the bugs this addresses (#21610, #8554) were closed by #22163.  The remaining issue #12437 is still open.  @holymonson can this be simplified if only aimed at that issue?
> Two of the bugs this addresses (#21610, #8554) were closed by #22163. The remaining issue #12437 is still open. @holymonson can this be simplified if only aimed at that issue?

This `Block`-level fix is not good if dispatching to `Series` could already fix some of them. I would rather close this (Or you might want to take the testcases).