0

I came across an unpredicted AttributeError when using the arccosh in Numpy. Here it is with Python 2:

>>> from numpy import arccosh
>>> arccosh(123456789012345678901)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'long' object has no attribute 'arccosh'

I found a similar error in Python 3.

Making the number a bit lower helps:

>>> arccosh(12345678901234567890)
44.65298496976247

While floats also works:

>>> arccosh(10**20)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'int' object has no attribute 'arccosh'
>>> arccosh(10.**20)
46.74484904044086

The exception also pops up for other functions, e.g., arcsinh, log10 and sin.

I suppose that the numbers are too long for numpy.uint64

>>> big = np.array([10**18], dtype=np.uint64)
>>> big = np.array([10**20], dtype=np.uint64)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: Python int too large to convert to C long

and that Numpy does not handle the numpy.object.

>>> big = np.array([10**20], dtype=np.object)
>>> arccosh(big)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'int' object has no attribute 'arccosh'

Python's acosh in the math module works:

>>> from math import acosh
>>> acosh(10**20)
46.74484904044086

I see an explanation here AttributeError: 'numpy.float64' object has no attribute 'log10' so while the error is explanable it is a bit surprising.

Finn Årup Nielsen
  • 6,130
  • 1
  • 33
  • 43
  • 1
    I'd say it's a NumPy bug, if it doesn't handle large integers properly. At least the error message should be clearer. Though I assume this bug is already reported somewhere on the NumPy repository. – 9769953 Jun 28 '18 at 09:39
  • 2
    Yup, reported as a NumPy bug (only six days ago): https://github.com/numpy/numpy/issues/11407 – 9769953 Jun 28 '18 at 09:40

0 Answers0