On Mon, Apr 14, 2014 at 1:09 PM, Warren Weckesser <
warren.weckes...@gmail.com> wrote:

> The test function numpy.testing.assert_equal fails when comparing -0.0 and
> 0.0:
>
> In [16]: np.testing.assert_equal(-0.0, 0.0)
> ---------------------------------------------------------------------------
> AssertionError                            Traceback (most recent call last)
> <ipython-input-16-4063bd6da228> in <module>()
> ----> 1 np.testing.assert_equal(-0.0, 0.0)
>
> /Users/warren/anaconda/lib/python2.7/site-packages/numpy/testing/utils.pyc
> in assert_equal(actual, desired, err_msg, verbose)
>     309         elif desired == 0 and actual == 0:
>     310             if not signbit(desired) == signbit(actual):
> --> 311                 raise AssertionError(msg)
>     312     # If TypeError or ValueError raised while using isnan and
> co, just handle
>     313     # as before
>
> AssertionError:
> Items are not equal:
>  ACTUAL: -0.0
>  DESIRED: 0.0
>
> There is code that checks for this specific case, so this is
> intentional.  But this is not consistent with how negative zeros in
> arrays are compared:
>
> In [22]: np.testing.assert_equal(np.array(-0.0), np.array(0.0))  # PASS
>
> In [23]: a = np.array([-0.0])
>
> In [24]: b = np.array([0.0])
>
> In [25]: np.testing.assert_array_equal(a, b)  # PASS
>
>
> Is there a reason the values are considered equal in an array, but not
> when compared as scalars?
>

Unlikely to be intentional. I expect this was a fix to assert_equal that
wasn't synced to assert_array_equal.

Ralf
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to