[Numpy-discussion] Is this a bug in repr ?
Tue Mar 15 11:20:52 CDT 2011
The usual expectation is that (when possible) repr() returns a value
that you can eval() to get the original data back. But,
>>> from numpy import *
>>> a = array( [ 16.50698631688883822 ] )
>>> b = eval(repr(a))
>>> import numpy.testing
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/stsci/pyssgdev/2.7/numpy/testing/utils.py", line 775, in
header=('Arrays are not almost equal to %d decimals' % decimal))
File "/usr/stsci/pyssgdev/2.7/numpy/testing/utils.py", line 618, in
Arrays are not almost equal to 15 decimals
x: array([ 16.50698632])
y: array([ 16.50698632])
I noticed this because a bunch of tests failed exactly this way. Of
course, the problem is that assert_array_almost_equal does not print
with the precision that it compared, which in turn happens because it
just uses repr() to convert the array.
I would expect that repr would print the values at least to the
resolution that they are stored, so I think this is a bug.
This happens with the current trunk of numpy in python 2.7 on Red Hat
Enterprise linux in 32 and 64 bits, and on Macintosh Leopard in 32
bits. I did not try any other configuration.
More information about the NumPy-Discussion