File tree 1 file changed +10
-8
lines changed
1 file changed +10
-8
lines changed Original file line number Diff line number Diff line change @@ -220,15 +220,17 @@ cdef int64_t cast_from_unit(
220
220
f" cannot convert input {ts} with the unit '{unit}'"
221
221
) from err
222
222
223
+ # In the event that ts itself is already an integer type, cast it to a
224
+ # 64-bit integer to ensure that frac will also be a 64-bit integer after
225
+ # type promotion changes in NEP 50. If this is not done, for example,
226
+ # np.int32 values for ts can lead to np.int32 values for frac, which can
227
+ # raise unexpected overflow errors downstream (GH 56996).
223
228
if isinstance (ts, np.integer):
224
- # If ts is an integer then the fractional component will always be
225
- # zero. It helps to set this explicitly following changes to type
226
- # promotion behavior in NEP 50 (GH 56996).
227
- frac = 0
228
- else :
229
- frac = ts - base
230
- if p:
231
- frac = round (frac, p)
229
+ ts = < int64_t> ts
230
+
231
+ frac = ts - base
232
+ if p:
233
+ frac = round (frac, p)
232
234
233
235
try :
234
236
return < int64_t> (base * m) + < int64_t> (frac * m)
You can’t perform that action at this time.
0 commit comments