<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Apr 14, 2014 at 1:09 PM, Warren Weckesser <span dir="ltr"><<a href="mailto:warren.weckesser@gmail.com" target="_blank">warren.weckesser@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The test function numpy.testing.assert_equal fails when comparing -0.0 and 0.0:<br>
<br>
In [16]: np.testing.assert_equal(-0.0, 0.0)<br>
---------------------------------------------------------------------------<br>
AssertionError Traceback (most recent call last)<br>
<ipython-input-16-4063bd6da228> in <module>()<br>
----> 1 np.testing.assert_equal(-0.0, 0.0)<br>
<br>
/Users/warren/anaconda/lib/python2.7/site-packages/numpy/testing/utils.pyc<br>
in assert_equal(actual, desired, err_msg, verbose)<br>
309 elif desired == 0 and actual == 0:<br>
310 if not signbit(desired) == signbit(actual):<br>
--> 311 raise AssertionError(msg)<br>
312 # If TypeError or ValueError raised while using isnan and<br>
co, just handle<br>
313 # as before<br>
<br>
AssertionError:<br>
Items are not equal:<br>
ACTUAL: -0.0<br>
DESIRED: 0.0<br>
<br>
There is code that checks for this specific case, so this is<br>
intentional. But this is not consistent with how negative zeros in<br>
arrays are compared:<br>
<br>
In [22]: np.testing.assert_equal(np.array(-0.0), np.array(0.0)) # PASS<br>
<br>
In [23]: a = np.array([-0.0])<br>
<br>
In [24]: b = np.array([0.0])<br>
<br>
In [25]: np.testing.assert_array_equal(a, b) # PASS<br>
<br>
<br>
Is there a reason the values are considered equal in an array, but not<br>
when compared as scalars?<br></blockquote><div><br></div><div>Unlikely to be intentional. I expect this was a fix to assert_equal that wasn't synced to assert_array_equal. <br></div></div><br></div><div class="gmail_extra">
Ralf<br><br></div></div>