Skip to content

np.testing.assert_almost_equal Issue in Python 3.5 for numpy==1.15.0 #11743

Closed
@foohyfooh

Description

@foohyfooh

The issues seems to be that in numpy/testing/_private/utils.py (x_id == y_id).all() on Line 707 is returning a bool in Python 3.5 and thus calling all on it is giving an AttributeError.
This is causing errors when testing the Pyrr package.

Note: This issue occurs with numpy==1.15.0 but not numpy==1.14.5

Reproducing code example:

This is one of the four code snippets that has the error is occurring.

from __future__ import absolute_import, division, print_function
try:
    import unittest2 as unittest
except:
    import unittest
import numpy as np
from pyrr import Quaternion, Matrix44, Matrix33, Vector3, Vector4, euler

class test_matrix_quaternion(unittest.TestCase):
    def test_m44_q_equivalence(self):
        """Test for equivalance of matrix and quaternion rotations.

        Create a matrix and quaternion, rotate each by the same values
        then convert matrix<->quaternion and check the results are the same.
        """
        m = Matrix44.from_x_rotation(np.pi / 2.)
        mq = Quaternion.from_matrix(m)

        q = Quaternion.from_x_rotation(np.pi / 2.)
        qm = Matrix44.from_quaternion(q)

        self.assertTrue(np.allclose(np.dot([1., 0., 0., 1.], m), [1., 0., 0., 1.]))
        self.assertTrue(np.allclose(np.dot([1., 0., 0., 1.], qm), [1., 0., 0., 1.]))

        self.assertTrue(np.allclose(q * Vector4([1., 0., 0., 1.]), [1., 0., 0., 1.]))
        self.assertTrue(np.allclose(mq * Vector4([1., 0., 0., 1.]), [1., 0., 0., 1.]))

        np.testing.assert_almost_equal(q, mq, decimal=5)
        np.testing.assert_almost_equal(m, qm, decimal=5)

Error message:

The errors can be found at https://travis-ci.org/adamlwgriffiths/Pyrr/jobs/415907003
Lines: 486, 502, 518, 534

The following is the Traceback from Travis CI

======================================================================
ERROR: Test for equivalance of matrix and quaternion rotations.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/adamlwgriffiths/Pyrr/pyrr/tests/objects/test_equivalence.py", line 29, in test_m44_q_equivalence
    np.testing.assert_almost_equal(q, mq, decimal=5)
  File "/home/travis/virtualenv/python3.5.6/lib/python3.5/site-packages/numpy/testing/_private/utils.py", line 568, in assert_almost_equal
    return assert_array_almost_equal(actual, desired, decimal, err_msg)
  File "/home/travis/virtualenv/python3.5.6/lib/python3.5/site-packages/numpy/testing/_private/utils.py", line 964, in assert_array_almost_equal
    precision=decimal)
  File "/home/travis/virtualenv/python3.5.6/lib/python3.5/site-packages/numpy/testing/_private/utils.py", line 736, in assert_array_compare
    flagged = func_assert_same_pos(x, y, func=isnan, hasval='nan')
  File "/home/travis/virtualenv/python3.5.6/lib/python3.5/site-packages/numpy/testing/_private/utils.py", line 707, in func_assert_same_pos
    if (x_id == y_id).all() != True:
AttributeError: 'bool' object has no attribute 'all'
======================================================================
ERROR: test_decompose (pyrr.tests.objects.test_matrix44.test_object_matrix44)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/adamlwgriffiths/Pyrr/pyrr/tests/objects/test_matrix44.py", line 326, in test_decompose
    np.testing.assert_almost_equal(m, expected_model)
  File "/home/travis/virtualenv/python3.5.6/lib/python3.5/site-packages/numpy/testing/_private/utils.py", line 568, in assert_almost_equal
    return assert_array_almost_equal(actual, desired, decimal, err_msg)
  File "/home/travis/virtualenv/python3.5.6/lib/python3.5/site-packages/numpy/testing/_private/utils.py", line 964, in assert_array_almost_equal
    precision=decimal)
  File "/home/travis/virtualenv/python3.5.6/lib/python3.5/site-packages/numpy/testing/_private/utils.py", line 736, in assert_array_compare
    flagged = func_assert_same_pos(x, y, func=isnan, hasval='nan')
  File "/home/travis/virtualenv/python3.5.6/lib/python3.5/site-packages/numpy/testing/_private/utils.py", line 707, in func_assert_same_pos
    if (x_id == y_id).all() != True:
AttributeError: 'bool' object has no attribute 'all'
======================================================================
ERROR: test_normalize (pyrr.tests.objects.test_vector3.test_object_vector3)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/adamlwgriffiths/Pyrr/pyrr/tests/objects/test_vector3.py", line 77, in test_normalize
    np.testing.assert_almost_equal(v.normalized, [0.57735, 0.57735, 0.57735], decimal=5)
  File "/home/travis/virtualenv/python3.5.6/lib/python3.5/site-packages/numpy/testing/_private/utils.py", line 568, in assert_almost_equal
    return assert_array_almost_equal(actual, desired, decimal, err_msg)
  File "/home/travis/virtualenv/python3.5.6/lib/python3.5/site-packages/numpy/testing/_private/utils.py", line 964, in assert_array_almost_equal
    precision=decimal)
  File "/home/travis/virtualenv/python3.5.6/lib/python3.5/site-packages/numpy/testing/_private/utils.py", line 736, in assert_array_compare
    flagged = func_assert_same_pos(x, y, func=isnan, hasval='nan')
  File "/home/travis/virtualenv/python3.5.6/lib/python3.5/site-packages/numpy/testing/_private/utils.py", line 707, in func_assert_same_pos
    if (x_id == y_id).all() != True:
AttributeError: 'bool' object has no attribute 'all'
======================================================================
ERROR: test_normalize (pyrr.tests.objects.test_vector4.test_object_vector4)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/adamlwgriffiths/Pyrr/pyrr/tests/objects/test_vector4.py", line 60, in test_normalize
    np.testing.assert_almost_equal(v.normalized, [0.5, 0.5, 0.5, 0.5], decimal=5)
  File "/home/travis/virtualenv/python3.5.6/lib/python3.5/site-packages/numpy/testing/_private/utils.py", line 568, in assert_almost_equal
    return assert_array_almost_equal(actual, desired, decimal, err_msg)
  File "/home/travis/virtualenv/python3.5.6/lib/python3.5/site-packages/numpy/testing/_private/utils.py", line 964, in assert_array_almost_equal
    precision=decimal)
  File "/home/travis/virtualenv/python3.5.6/lib/python3.5/site-packages/numpy/testing/_private/utils.py", line 736, in assert_array_compare
    flagged = func_assert_same_pos(x, y, func=isnan, hasval='nan')
  File "/home/travis/virtualenv/python3.5.6/lib/python3.5/site-packages/numpy/testing/_private/utils.py", line 707, in func_assert_same_pos
    if (x_id == y_id).all() != True:
AttributeError: 'bool' object has no attribute 'all'

Numpy/Python version information:

1.15.0 3.5.5 |Anaconda, Inc.| (default, Apr 7 2018, 04:52:34) [MSC v.1900 64 bit (AMD64)]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions