Skip to content

Commit 1bf5642

Browse files
committed
handle missed corner case
1 parent 67f98f1 commit 1bf5642

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

pandas/core/arrays/datetimes.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -1698,13 +1698,9 @@ def _generate_regular_range(cls, start, end, periods, freq):
16981698
e = _generate_range_overflow_safe(b, periods, stride, side='start')
16991699
tz = start.tz
17001700
elif end is not None:
1701-
e = Timestamp(end).value
1701+
e = Timestamp(end).value + stride
17021702
b = _generate_range_overflow_safe(e, periods, stride, side='end')
17031703
tz = end.tz
1704-
1705-
# add an additional step to `e` because np.arange(b, e) will
1706-
# not include `e`
1707-
e += stride
17081704
else:
17091705
raise ValueError("at least 'start' or 'end' should be specified "
17101706
"if a 'period' is given.")
@@ -1753,10 +1749,10 @@ def _generate_range_overflow_safe(endpoint, periods, stride,
17531749
# GH#14187 raise instead of incorrectly wrapping around
17541750
assert side in ['start', 'end']
17551751

1756-
i64max = np.iinfo(np.int64).max
1752+
i64max = np.uint64(np.iinfo(np.int64).max)
17571753
msg = ('Cannot generate range with {side}={endpoint} and '
17581754
'periods={periods}'
1759-
.format(side=side, endpoint=Timestamp(endpoint), periods=periods))
1755+
.format(side=side, endpoint=endpoint, periods=periods))
17601756

17611757
with np.errstate(over="raise"):
17621758
# if periods * strides cannot be multiplied within the *uint64* bounds,
@@ -1776,6 +1772,12 @@ def _generate_range_overflow_safe(endpoint, periods, stride,
17761772
# no chance of not-overflowing
17771773
raise tslib.OutOfBoundsDatetime(msg)
17781774

1775+
elif (side == 'end' and endpoint > i64max and endpoint - stride <= i64max):
1776+
# in _generate_regular_range we added `stride` thereby overflowing
1777+
# the bounds. Adjust to fix this.
1778+
return _generate_range_overflow_safe(endpoint - stride,
1779+
periods - 1, stride, side)
1780+
17791781
# split into smaller pieces
17801782
return _generate_range_recurse(endpoint, periods, stride, side)
17811783

0 commit comments

Comments
 (0)