-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
COMPAT: periods needs coercion to np.int64 in _generate_regular_range #8943
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hey @jreback, I'd like to try tackling this one as a first PR. Do you mind giving an example line of code that would cause I thought maybe it was this line, but I couldn't find an example. I tried
but in my case, |
you actually need a bigger number try np.iinfo(np.int32) + 1 |
Sorry, I'm probably being a bit dense here, but are you suggesting I try something like:
In that case, the overflow happens on the second line. I can't think of how to produe an overflow inside |
look at @jorisvandenbossche example in the linked issue #8907 |
Cool, I think I know why I wasn't able to reproduce the bug. @jorisvandenbossche is on 32-bit Linux and I'm on 64-bit Linux, so for me, Alright, I'll do your proposed fix now. |
In _generate_regular_range, we explicitly cast `periods` to np.int64 to prevent overflow in the function tseries.index._generate_regular_range. Note: we don't bother casting it for the function call generate_range since there's no danger of overflow in that function.
Closes #8943: COMPAT: periods needs coercion to np.int64
https://github.com/pydata/pandas/blob/master/pandas/tseries/index.py#L1768
a simple
np.int64(periods)
will suffice(and tests of course)
This needs to guaranteed to be int64 as a result (e.g. if this is in32 it will have an internal overflow which will make it have a valid but weird result)
The text was updated successfully, but these errors were encountered: