Skip to content
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

AttributeError when taking sine of huge number #13875

Closed
cool-RR opened this issue Jun 30, 2019 · 5 comments
Closed

AttributeError when taking sine of huge number #13875

cool-RR opened this issue Jun 30, 2019 · 5 comments

Comments

@cool-RR
Copy link

cool-RR commented Jun 30, 2019

import numpy as np
np.sin(70**11)

Error message:

Traceback (most recent call last):                 
  File "a.py", line 2, in <module>                 
    np.sin(70**11)                                 
AttributeError: 'int' object has no attribute 'sin'

Numpy/Python version information:

1.16.4 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit (AMD64)]
@eric-wieser
Copy link
Member

eric-wieser commented Jun 30, 2019

Fixed in #12700 to produce a better error message, now gives:

>>> np.sin(70**11)
AttributeError: 'int' object has no attribute 'sin'

The above exception was the direct cause of the following exception:

TypeError: loop of ufunc does not support argument 0 of type int which has no callable sin method

Passing a float as np.sin(70.0**11) will work fine

@cool-RR
Copy link
Author

cool-RR commented Jun 30, 2019

Maybe I'm missing something, but the "fixed" version still seems like a completely opaque error message.

Someone runs np.sin(7) and it works, and suddenly for a big number it doesn't work. Shouldn't the error message be something like Input is too large to calculate sin, use float?

@seberg
Copy link
Member

seberg commented Jun 30, 2019

Until we get rid of automatic coercion to an object array this is probably about as good as it will get. We could maybe make the error message spell out a bit more things, but we cannot just put in "input is too large" or so, at the point where the error message happens that would just be guessing. Although maybe you can suggest a wording which makes things easier.

@cool-RR
Copy link
Author

cool-RR commented Jun 30, 2019

Can't the error catching logic check whether this is an int which is above a certain threshold, and then use the "int is too large" message?

@eric-wieser
Copy link
Member

eric-wieser commented Jun 30, 2019

No, because np.sin(np.array(1, dtype=object)) has the same problem.

The cause here is:

  • 70**11 is not an array, so is coerced to one
  • 70**11 is too large to fit in an int64 array, so an object array types is chosen
  • np.sin(object_array) is only supported if the objects within have a sin method

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