Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Misleading error when using ufuncs on large python ints #8357

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

Closed
maxnoe opened this issue Dec 8, 2016 · 5 comments
Closed

Misleading error when using ufuncs on large python ints #8357

maxnoe opened this issue Dec 8, 2016 · 5 comments

Comments

@maxnoe
Copy link

maxnoe commented Dec 8, 2016

In [2]: import numpy as np
In [2]: np.log10(2**10)
Out[2]: 3.0102999566398121
In [3]: np.log10(2**64)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-3-a2d6ba68c7f4> in <module>()
----> 1 np.log10(2**64)

AttributeError: 'int' object has no attribute 'log10

I guess this is because python's unlimited precision int cannot be transformed into a 64 bit unsigned int anymore. But the error message is very misleading on this.

@charris
Copy link
Member

charris commented Dec 8, 2016

Really, the only other thing to do is raise an error message when the number is converted to an object array. The automatic conversion of some types to object arrays causes other problems as well, and we may change that behavior at some point.

@maxnoe
Copy link
Author

maxnoe commented Dec 8, 2016

I fully agree that this should raise an error instead of silently converting to a float number. But the error message should be a more specific.

@charris
Copy link
Member

charris commented Dec 8, 2016

What would you suggest? The number gets converted to an object array that contains a long integer object. Since all types of objects can be in object arrays, the log function doesn't know how to handle it besides looking for an appropriate object method to call, which is missing in this case, and that is what the error message tells you. It is only confusing if you don't know what is going on, but the function has no idea how you got to the point where it is called, so cannot help you much in that regard.

@eric-wieser
Copy link
Member

I think that in general, calling np.func on a object array should wrap the error message. So for instance, something like:

>>> class Foo: pass
>>> np.log10(Foo())
TypeError: Cannot call log10 on an object array when the element <__main__.Foo object at 0x000001EC87E80B00> has no 'log10' attribute

@eric-wieser
Copy link
Member

Fixed in #12700

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants