[Numpy-discussion] Is this a bug in repr ?

Charles R Harris charlesr.harris@gmail....
Tue Mar 15 12:39:58 CDT 2011


On Tue, Mar 15, 2011 at 10:20 AM, Mark Sienkiewicz <sienkiew@stsci.edu>wrote:

> 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))
>  >>> a-b
> array([ -3.11116111e-09])
>  >>> import numpy.testing
>  >>> numpy.testing.assert_array_almost_equal(a,b,decimal=15)
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
>  File "/usr/stsci/pyssgdev/2.7/numpy/testing/utils.py", line 775, in
> assert_array_almost_equal
>    header=('Arrays are not almost equal to %d decimals' % decimal))
>  File "/usr/stsci/pyssgdev/2.7/numpy/testing/utils.py", line 618, in
> assert_array_compare
>    raise AssertionError(msg)
> AssertionError:
> Arrays are not almost equal to 15 decimals
>
> (mismatch 100.0%)
>  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.
>
>
Yes, I think it is a bug. IIRC, it also shows up for object arrays.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20110315/a41d78aa/attachment.html 


More information about the NumPy-Discussion mailing list