Fix wraparound/overflow in date_range
State: closed

- [x] closes #14187 
- [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: Error Reporting
description: Incorrect or improved errors from pandas

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

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

```diff
@@            Coverage Diff             @@
##           master   #19740      +/-   ##
==========================================
+ Coverage   91.58%    91.6%   +0.02%     
==========================================
  Files         150      150              
  Lines       48862    48873      +11     
==========================================
+ Hits        44750    44770      +20     
+ Misses       4112     4103       -9
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `89.98% <100%> (+0.02%)` | :arrow_up: |
| #single | `41.79% <63.63%> (+0.04%)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/19740?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/indexes/datetimes.py](https://codecov.io/gh/pandas-dev/pandas/pull/19740/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9kYXRldGltZXMucHk=) | `95.35% <100%> (+0.03%)` | :arrow_up: |
| [pandas/core/ops.py](https://codecov.io/gh/pandas-dev/pandas/pull/19740/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvb3BzLnB5) | `96.45% <0%> (-0.39%)` | :arrow_down: |
| [pandas/util/testing.py](https://codecov.io/gh/pandas-dev/pandas/pull/19740/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvdGVzdGluZy5weQ==) | `83.64% <0%> (-0.21%)` | :arrow_down: |
| [pandas/core/indexes/base.py](https://codecov.io/gh/pandas-dev/pandas/pull/19740/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9iYXNlLnB5) | `96.45% <0%> (-0.01%)` | :arrow_down: |
| [pandas/core/arrays/categorical.py](https://codecov.io/gh/pandas-dev/pandas/pull/19740/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL2NhdGVnb3JpY2FsLnB5) | `94.9% <0%> (+0.01%)` | :arrow_up: |
| [pandas/core/indexes/category.py](https://codecov.io/gh/pandas-dev/pandas/pull/19740/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9jYXRlZ29yeS5weQ==) | `97.31% <0%> (+0.03%)` | :arrow_up: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/19740/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.22% <0%> (+0.06%)` | :arrow_up: |
| [pandas/plotting/\_converter.py](https://codecov.io/gh/pandas-dev/pandas/pull/19740/diff?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL19jb252ZXJ0ZXIucHk=) | `66.95% <0%> (+1.73%)` | :arrow_up: |

------

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

``from pandas.core.algorithms import checked_add_with_arr``
does it all

> `from pandas.core.algorithms import checked_add_with_arr` does it all

OK.  Do we care about catching OverflowError and re-raising as OutOfBoundsDatetime?  If not then this is super-simple.  If so then most of the code added here is still needed.
i think we should reraise as oob 
Agreed. Done.
this closes #14187 pls add appropriate tests from that issue
> this closes #14187 pls add appropriate tests from that issue

I'll add the GH reference to the test already implemented.  That test covers the 14187's example almost exactly; only difference is the starting date passed to date_range.
> well the original impl you had a badly written version of checked_add_with_arr

I call BS.  You're welcome to be demanding but I won't accept aspersions given that it was literally just wrapping the one line that is already there.  Closing.