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

[5.0RC1] wrong assertion in a failed vo_test.py::TestParse::test_doubleComplex (on mips64el) #12416

Open
olebole opened this issue Nov 5, 2021 · 1 comment

Comments

@olebole
Copy link
Member

olebole commented Nov 5, 2021

Description

This is actually a two-fold bug: one is a failure on mips64el, mipsel, hppa, and the other is that the failure uncovers the use of a wrong assertion.

Expected behavior

This failure happened already before (since ~2019), so it is not new. I actually think this may be connected rather to some pecularities on these platforms then to a bug in astropy, and usually this is just set to xfail locally. However, probably the "The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()" should be fixed, although probably more cosmetic.

Actual behavior

On mips64el, mipsel, hppa, I get the following failure during test:

_________________________ TestParse.test_doubleComplex _________________________

comparison = <built-in function eq>
x = masked_array(data=[--, 0j, -1j, --, --],
             mask=[ True, False, False,  True,  True],
       fill_value=(1e+20+0j))
y = array([nan +0.j,  0. +0.j,  0. -1.j, nan+infj, nan +0.j]), err_msg = ''
verbose = True
header = 'error during assertion:\n\nTraceback (most recent call last):\n  File "/usr/lib/python3/dist-packages/numpy/testing/_... The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()\n\n\nArrays are not equal'
precision = 6, equal_nan = True, equal_inf = True

    def assert_array_compare(comparison, x, y, err_msg='', verbose=True,
                             header='', precision=6, equal_nan=True,
                             equal_inf=True):
[…]
                if equal_inf:
>                   flagged |= func_assert_same_pos(x, y,
                                                    func=lambda xy: xy == +inf,
                                                    hasval='+inf')

/usr/lib/python3/dist-packages/numpy/testing/_private/utils.py:767: 
[…]
        if isinstance(check, (np.bool_, bool)):
>           return masked if mask else check
E           ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

/usr/lib/python3/dist-packages/numpy/ma/core.py:4078: ValueError

During handling of the above exception, another exception occurred:

self = <astropy.io.votable.tests.vo_test.TestParse object at 0xffd8593340>

    def test_doubleComplex(self):
        assert issubclass(self.array['doubleComplex'].dtype.type,
                          np.complex128)
>       assert_array_equal(
            self.array['doubleComplex'],
            [np.nan+0j, 0+0j, 0+-1j, np.nan+(np.inf*1j), np.nan+0j])
E       ValueError: 
E       error during assertion:
E       
E       Traceback (most recent call last):
E         File "/usr/lib/python3/dist-packages/numpy/testing/_private/utils.py", line 767, in assert_array_compare
E           flagged |= func_assert_same_pos(x, y,
E         File "/usr/lib/python3/dist-packages/numpy/testing/_private/utils.py", line 722, in func_assert_same_pos
E           x_id = func(x)
E         File "/usr/lib/python3/dist-packages/numpy/testing/_private/utils.py", line 768, in <lambda>
E           func=lambda xy: xy == +inf,
E         File "/usr/lib/python3/dist-packages/numpy/ma/core.py", line 4116, in __eq__
E           return self._comparison(other, operator.eq)
E         File "/usr/lib/python3/dist-packages/numpy/ma/core.py", line 4078, in _comparison
E           return masked if mask else check
E       ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
E       
E       
E       Arrays are not equal
E        x: MaskedArray([inf+infj,  0. +0.j,  0. -1.j, inf+infj, inf+infj])
E        y: array([nan +0.j,  0. +0.j,  0. -1.j, nan+infj, nan +0.j])

astropy/io/votable/tests/vo_test.py:478: ValueError

Full build/test log

Steps to Reproduce

This should happen reproducibly when you run the tests on mips64el, mips, or hppa architectures.

System Details

platform linux -- Python 3.9.7, pytest-6.2.5, py-1.10.0, pluggy-0.13.0 -- /usr/bin/python3.9
cachedir: .pytest_cache
Matplotlib: 3.3.4
Freetype: 2.11.0

Running tests with Astropy version 5.0-rc1.
Running tests in .pybuild/cpython3_3.9/build.

Date: 2021-11-05T08:52:28

Platform: Linux-5.10.0-9-loongson-3-mips64-with-glibc2.32

Executable: /usr/bin/python3.9

Full Python Version:
3.9.7 (default, Sep 24 2021, 09:43:00)
[GCC 10.3.0]

encodings: sys: utf-8, locale: UTF-8, filesystem: utf-8
byteorder: little
float info: dig: 15, mant_dig: 15

Package versions:
Numpy: 1.19.5
Scipy: 1.7.1
Matplotlib: 3.3.4
h5py: 3.3.0
Pandas: 1.1.5
PyERFA: 2.0.0
Cython: 0.29.24
Scikit-image: 0.18.3
asdf: not available
pyarrow: not available

Using Astropy options: remote_data: none.

hypothesis profile 'ci' -> database=None, deadline=None, print_blob=True, derandomize=True
ARCH_ON_CI: undefined
IS_CRON: undefined

rootdir: /<>, configfile: setup.cfg
plugins: mpl-0.11, remotedata-0.3.2, openfiles-0.5.0, mock-3.6.1, filter-subpackage-0.1.1, doctestplus-0.11.0, cov-3.0.0, astropy-header-0.1.2, arraydiff-0.3, hypothesis-5.43.3

@olebole olebole added the Bug label Nov 5, 2021
@mhvk
Copy link
Contributor

mhvk commented Nov 6, 2021

@olebole - thanks for the report. I'm not quite familiar enough with votable to know exactly what the expectation is, but on the astropy side it is certainly not good to compare a MaskedArray with a plain one - I think if one cares about the underlying data, one should compare self.array['doubleComplex'].data. Though as you note, the underlying data clearly are not consistent, probably because for some reason those platforms deal with nan a bit differently, and it may indeed be simplest to just skip the test (or only check that the unmasked data match).

As for the other failure, that actually seems to be a numpy bug... Though I cannot reproduce it on my amd64 system with the same inputs...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants