You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Python long raises OverflowError while same value as np.uint64 does not. #5612
Trying to assign a value of 2**64 - 1 to an array of dtype uint64 raises an OverflowError, but only if the value is a Python long rather than a Numpy scalar. This seems like a bug to me because the value obviously doesn't overflow and they compare equal.
It only happens when using fill, not when doing a direct assignment:
>>> a = np.empty(1, np.uint64)
>>> a[0] = 2**64 - 1
>>> a.fill(2**64-1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OverflowError: int too big to convert
This points to PyArray_FillWithScalar as the culprit, and I think it is indeed to blame: when converting integer types, it calls PyLong_AsLongLong, and doesn't try with PyLong_AsUnsignedLongLong if that fails, see here for the numpy code.
Activity
jaimefrio commentedon Feb 27, 2015
It only happens when using
fill, not when doing a direct assignment:This points to
PyArray_FillWithScalaras the culprit, and I think it is indeed to blame: when converting integer types, it callsPyLong_AsLongLong, and doesn't try withPyLong_AsUnsignedLongLongif that fails, see here for the numpy code.PRs are welcome...
johntyree commentedon Feb 28, 2015
A real bug and not just pebkac! How exciting! I'll try to put together a PR this weekend.
Update to 1.9.2
Update to 1.9.2