-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
python large integer conversion to object #7547
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
The easy work around on the user side would be to use a big float rather than an integer. On the numpy end, IIRC, we already do a two pass conversion, once for type and a second for value, so this might be a bug in that. |
Yes, in my post to matplotlib I suggest to convert the integer to numpy.float such that no (very wasteful) numpy array of dtype numpy.object is created unintentionally. Nevertheless, this is something that could occur in other not well-crafted code at times as well, or for beginners, and then the suggested solution would be an easy resolution over getting an error message (though, as you say, really the user code should be fixed in the long run). This behaviour only occurs for large integers that do not fit into int64, so the behaviour changes with size of the python integer, which could be non-obvious in simple tests. |
Going to close it, while the fact that There are more subtleties, and probably some functions which will do the wrong things: Those should be considered bugs to be squared when they come up, this isn't an example for that. |
I was trying to plot something in matplotlib/pylab using
which would result in some error message. I use python 3.5.1, numpy 1.11.0, matplotlib 1.5.1
The error arise because somewhere in the matplotlib internals a large integer is added to an array of float64, the result, however is a numpy array of dtype numpy.object with python floats as members
with output
similar for multiplication. I assume this originates from conversion of the scalar to a np.ndarray before the mathematical operation, which seems reasonable at first, but has bad results in the end.
Wouldn't it be better if the default behaviour for the first case was dtype of np.float64 by default, and if one wanted a non-native (numpy.object) type this has to be specified explicitly, such that
The currently resulting array now (with matplotlib) causes the crash when they try to apply some round operation
The easiest fix at this point would be convert the array to a float array before applying round in round_, changing it to
It probably should be fixed in matplotlib/ticker class in the first place (matplotlib/matplotlib#6301). Nevertheless, I think the proposed change is a reasonable behaviour for the round_ function instead of giving an error for the case when it is passed an array of python float or integer objects.
The text was updated successfully, but these errors were encountered: