Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vector3 incompatible with general numpy functionality ( numpy.testing.assert_almost_equal ) #115

Open
manuel-koch opened this issue Nov 23, 2022 · 0 comments

Comments

@manuel-koch
Copy link

Within a unit test I try to compare to Vector3 instances for almost-equality using the standard numpy test function assert_almost_equal but that raises an exception.
Vector3 equal method seems override the magic equal method in a way that is incompatible with general numpy functionality:

Using pyrr==0.10.3 and numpy==1.23.4

Python 3.10.6 (main, Sep 29 2022, 10:59:18) [Clang 14.0.0 (clang-1400.0.29.102)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from pyrr import Vector3
>>> from numpy.testing import assert_almost_equal
>>> a = Vector3([1,2,3])
>>> b = Vector3([1,2,3])
>>> assert_almost_equal(a,b)
Traceback (most recent call last):
  File ".../lib/python3.10/site-packages/numpy/testing/_private/utils.py", line 771, in assert_array_compare
    flagged |= func_assert_same_pos(x, y,
  File ".../lib/python3.10/site-packages/numpy/testing/_private/utils.py", line 727, in func_assert_same_pos
    x_id = func(x)
  File ".../lib/python3.10/site-packages/numpy/testing/_private/utils.py", line 772, in <lambda>
    func=lambda xy: xy == +inf,
  File ".../lib/python3.10/site-packages/multipledispatch/dispatcher.py", line 435, in __call__
    return func(self.obj, *args, **kwargs)
  File ".../lib/python3.10/site-packages/pyrr/objects/vector3.py", line 129, in __eq__
    self._unsupported_type('EQ', other)
  File ".../lib/python3.10/site-packages/pyrr/objects/base.py", line 25, in _unsupported_type
    raise ValueError('Cannot {} a {} to a {}'.format(method, type(other).__name__, type(self).__name__))
ValueError: Cannot EQ a float to a Vector3

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../lib/python3.10/site-packages/numpy/testing/_private/utils.py", line 583, in assert_almost_equal
    return assert_array_almost_equal(actual, desired, decimal, err_msg)
  File ".../lib/python3.10/site-packages/numpy/testing/_private/utils.py", line 1046, in assert_array_almost_equal
    assert_array_compare(compare, x, y, err_msg=err_msg, verbose=verbose,
  File ".../lib/python3.10/site-packages/numpy/testing/_private/utils.py", line 852, in assert_array_compare
    raise ValueError(msg)
ValueError: 
error during assertion:

Traceback (most recent call last):
  File ".../lib/python3.10/site-packages/numpy/testing/_private/utils.py", line 771, in assert_array_compare
    flagged |= func_assert_same_pos(x, y,
  File ".../lib/python3.10/site-packages/numpy/testing/_private/utils.py", line 727, in func_assert_same_pos
    x_id = func(x)
  File ".../lib/python3.10/site-packages/numpy/testing/_private/utils.py", line 772, in <lambda>
    func=lambda xy: xy == +inf,
  File ".../lib/python3.10/site-packages/multipledispatch/dispatcher.py", line 435, in __call__
    return func(self.obj, *args, **kwargs)
  File ".../lib/python3.10/site-packages/pyrr/objects/vector3.py", line 129, in __eq__
    self._unsupported_type('EQ', other)
  File ".../lib/python3.10/site-packages/pyrr/objects/base.py", line 25, in _unsupported_type
    raise ValueError('Cannot {} a {} to a {}'.format(method, type(other).__name__, type(self).__name__))
ValueError: Cannot EQ a float to a Vector3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant