@@ -54,6 +54,8 @@ def generate_regular_range(
54
54
iend = end ._value if end is not None else None
55
55
freq .nanos # raises if non-fixed frequency
56
56
td = Timedelta (freq )
57
+ b : int | np .int64 | np .uint64
58
+ e : int | np .int64 | np .uint64
57
59
try :
58
60
td = td .as_unit ( # pyright: ignore[reportGeneralTypeIssues]
59
61
unit , round_ok = False
@@ -96,7 +98,7 @@ def generate_regular_range(
96
98
97
99
def _generate_range_overflow_safe (
98
100
endpoint : int , periods : int , stride : int , side : str = "start"
99
- ) -> int :
101
+ ) -> np . int64 | np . uint64 :
100
102
"""
101
103
Calculate the second endpoint for passing to np.arange, checking
102
104
to avoid an integer overflow. Catch OverflowError and re-raise
@@ -115,7 +117,7 @@ def _generate_range_overflow_safe(
115
117
116
118
Returns
117
119
-------
118
- other_end : int
120
+ other_end : np.int64 | np.uint64
119
121
120
122
Raises
121
123
------
@@ -157,13 +159,13 @@ def _generate_range_overflow_safe(
157
159
remaining = periods - mid_periods
158
160
assert 0 < remaining < periods , (remaining , periods , endpoint , stride )
159
161
160
- midpoint = _generate_range_overflow_safe (endpoint , mid_periods , stride , side )
162
+ midpoint = int ( _generate_range_overflow_safe (endpoint , mid_periods , stride , side ) )
161
163
return _generate_range_overflow_safe (midpoint , remaining , stride , side )
162
164
163
165
164
166
def _generate_range_overflow_safe_signed (
165
167
endpoint : int , periods : int , stride : int , side : str
166
- ) -> int :
168
+ ) -> np . int64 | np . uint64 :
167
169
"""
168
170
A special case for _generate_range_overflow_safe where `periods * stride`
169
171
can be calculated without overflowing int64 bounds.
@@ -181,9 +183,7 @@ def _generate_range_overflow_safe_signed(
181
183
# Putting this into a DatetimeArray/TimedeltaArray
182
184
# would incorrectly be interpreted as NaT
183
185
raise OverflowError
184
- # error: Incompatible return value type (got "signedinteger[_64Bit]",
185
- # expected "int")
186
- return result # type: ignore[return-value]
186
+ return result
187
187
except (FloatingPointError , OverflowError ):
188
188
# with endpoint negative and addend positive we risk
189
189
# FloatingPointError; with reversed signed we risk OverflowError
@@ -198,15 +198,11 @@ def _generate_range_overflow_safe_signed(
198
198
# exceed implementation bounds, but when passing the result to
199
199
# np.arange will get a result slightly within the bounds
200
200
201
- # error: Incompatible types in assignment (expression has type
202
- # "unsignedinteger[_64Bit]", variable has type "signedinteger[_64Bit]")
203
- result = np .uint64 (endpoint ) + np .uint64 (addend ) # type: ignore[assignment]
201
+ uresult = np .uint64 (endpoint ) + np .uint64 (addend )
204
202
i64max = np .uint64 (i8max )
205
- assert result > i64max
206
- if result <= i64max + np .uint64 (stride ):
207
- # error: Incompatible return value type (got "unsignedinteger", expected
208
- # "int")
209
- return result # type: ignore[return-value]
203
+ assert uresult > i64max
204
+ if uresult <= i64max + np .uint64 (stride ):
205
+ return uresult
210
206
211
207
raise OutOfBoundsDatetime (
212
208
f"Cannot generate range with { side } ={ endpoint } and periods={ periods } "
0 commit comments