BUG: avoid overflow in Bday generate_range, closes #24252
State: closed

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


Labels:
name: Error Reporting
description: Incorrect or improved errors from pandas
name: Frequency
description: DateOffsets
name: Timezones
description: Timezone data dtype

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

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

```diff
@@            Coverage Diff             @@
##           master   #26651      +/-   ##
==========================================
- Coverage   91.87%   91.87%   -0.01%     
==========================================
  Files         174      174              
  Lines       50692    50696       +4     
==========================================
+ Hits        46575    46576       +1     
- Misses       4117     4120       +3
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.41% <100%> (ø)` | :arrow_up: |
| #single | `41.8% <50%> (-0.07%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/26651?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/tseries/offsets.py](https://codecov.io/gh/pandas-dev/pandas/pull/26651/diff?src=pr&el=tree#diff-cGFuZGFzL3RzZXJpZXMvb2Zmc2V0cy5weQ==) | `96.7% <100%> (+0.01%)` | :arrow_up: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/26651/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `78.94% <0%> (-10.53%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/26651/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97% <0%> (-0.12%)` | :arrow_down: |
| [pandas/util/testing.py](https://codecov.io/gh/pandas-dev/pandas/pull/26651/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvdGVzdGluZy5weQ==) | `90.91% <0%> (+0.1%)` | :arrow_up: |

------

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

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

```diff
@@            Coverage Diff             @@
##           master   #26651      +/-   ##
==========================================
- Coverage   91.87%   91.86%   -0.02%     
==========================================
  Files         180      180              
  Lines       50746    50751       +5     
==========================================
- Hits        46623    46621       -2     
- Misses       4123     4130       +7
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.45% <100%> (-0.01%)` | :arrow_down: |
| #single | `41.09% <33.33%> (-0.1%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/26651?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/tseries/offsets.py](https://codecov.io/gh/pandas-dev/pandas/pull/26651/diff?src=pr&el=tree#diff-cGFuZGFzL3RzZXJpZXMvb2Zmc2V0cy5weQ==) | `96.36% <100%> (-0.33%)` | :arrow_down: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/26651/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `88.88% <0%> (-11.12%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/26651/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `96.89% <0%> (-0.12%)` | :arrow_down: |
| [pandas/util/testing.py](https://codecov.io/gh/pandas-dev/pandas/pull/26651/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvdGVzdGluZy5weQ==) | `90.94% <0%> (+0.1%)` | :arrow_up: |

------

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

This doesn't solve the overflow type:

```python
>>> date = pd.Timestamp.max.floor("D").to_pydatetime().date()  # datetime.date(2262, 4, 11)
>>> freq = 'B'
>>> pd.date_range(date, periods=2, freq=freq)  # see periods=2
OverflowError: int too big to convert
```

I would guess this should be a ``OutOfBoundsDatetime`` and not a OverflowError?
Yah, it should probably be an OutOfBoundsDatetime instead of OverflowError.  Will update.
lgtm. ping when green. 
code & tests lgtm. can you add a whatsnew. ping on green.
ping
In one Travis build I'm seeing an error I also get locally on many branches:

```
_______ TestDataFrameConstructors.test_constructor_maskedrecarray_dtype ________
[gw1] linux -- Python 3.7.3 /home/travis/miniconda3/envs/pandas-dev/bin/python
self = <pandas.tests.frame.test_constructors.TestDataFrameConstructors object at 0x7fa6ace49f98>
    def test_constructor_maskedrecarray_dtype(self):
        # Ensure constructor honors dtype
        data = np.ma.array(
            np.ma.zeros(5, dtype=[('date', '<f8'), ('price', '<f8')]),
            mask=[False] * 5)
>       data = data.view(ma.mrecords.mrecarray)
E       AttributeError: module 'numpy.ma' has no attribute 'mrecords'
```

Any idea what this is all about?
Not sure, but `numpy.ma.mrecords` doesn't seem to be imported by default. Would need `import numpy.ma.mrecords` before using `ma.mrecords`.
Looks like we import ma.mrecords as a runtime import in the DataFrame constructor, so this ma.mrecords will not exist if we run these tests before that runtime import gets hit.  (I'm guessing we started randomizing test order recently?).  Just added the import in the appropriate place in the test so it shouldn't matter anymore.
thanks @jbrockmendel nice patch!