Skip to content

Incorrect behavior of np.testing.assert_array_almost_equal on linux, windows #11121

@taldcroft

Description

@taldcroft

I get the following unexpected exception / test failure on linux (CentOS-6) and Windows but not on Mac. This was driven by a CI failure that showed up for linux / windows but no on my local Mac version.

In [62]: c = np.ma.MaskedArray([3.4, 4.1, 6.3], mask=[False, True, False])

In [63]: np.testing.assert_array_almost_equal(c[:2], [3.4, np.nan])

In [64]: np.testing.assert_array_almost_equal(c, [3.4, np.nan, 6.3])
/export/tom/anaconda/envs/astropy/lib/python3.6/site-packages/numpy/core/arrayprint.py:686: UserWarning: Warning: converting a masked element to nan.
  s = self.format % x
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/export/tom/anaconda/envs/astropy/lib/python3.6/site-packages/numpy/testing/utils.py in assert_array_compare(comparison, x, y, err_msg, verbose, header, precision, equal_nan, equal_inf)
    760 
--> 761         val = comparison(x, y)
    762 

/export/tom/anaconda/envs/astropy/lib/python3.6/site-packages/numpy/testing/utils.py in compare(x, y)
    952         y = array(y, dtype=dtype, copy=False, subok=True)
--> 953         z = abs(x - y)
    954 

/export/tom/anaconda/envs/astropy/lib/python3.6/site-packages/numpy/ma/core.py in __sub__(self, other)
   4078             return NotImplemented
-> 4079         return subtract(self, other)
   4080 

/export/tom/anaconda/envs/astropy/lib/python3.6/site-packages/numpy/ma/core.py in __call__(self, a, b, *args, **kwargs)
   1045             np.seterr(divide='ignore', invalid='ignore')
-> 1046             result = self.f(da, db, *args, **kwargs)
   1047         # Get the mask for the result

ValueError: operands could not be broadcast together with shapes (3,) (2,) 

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
<ipython-input-64-2c7b42e22a4d> in <module>()
----> 1 np.testing.assert_array_almost_equal(c, [3.4, np.nan, 6.3])

/export/tom/anaconda/envs/astropy/lib/python3.6/site-packages/numpy/testing/utils.py in assert_array_almost_equal(x, y, decimal, err_msg, verbose)
    960     assert_array_compare(compare, x, y, err_msg=err_msg, verbose=verbose,
    961              header=('Arrays are not almost equal to %d decimals' % decimal),
--> 962              precision=decimal)
    963 
    964 

/export/tom/anaconda/envs/astropy/lib/python3.6/site-packages/numpy/testing/utils.py in assert_array_compare(comparison, x, y, err_msg, verbose, header, precision, equal_nan, equal_inf)
    784         msg = build_err_msg([x, y], err_msg, verbose=verbose, header=header,
    785                             names=('x', 'y'), precision=precision)
--> 786         raise ValueError(msg)
    787 
    788 

ValueError: 
error during assertion:

Traceback (most recent call last):
  File "/export/tom/anaconda/envs/astropy/lib/python3.6/site-packages/numpy/testing/utils.py", line 761, in assert_array_compare
    val = comparison(x, y)
  File "/export/tom/anaconda/envs/astropy/lib/python3.6/site-packages/numpy/testing/utils.py", line 953, in compare
    z = abs(x - y)
  File "/export/tom/anaconda/envs/astropy/lib/python3.6/site-packages/numpy/ma/core.py", line 4079, in __sub__
    return subtract(self, other)
  File "/export/tom/anaconda/envs/astropy/lib/python3.6/site-packages/numpy/ma/core.py", line 1046, in __call__
    result = self.f(da, db, *args, **kwargs)
ValueError: operands could not be broadcast together with shapes (3,) (2,) 


Arrays are not almost equal to 6 decimals
 x: MaskedArray([ 3.4,  nan,  6.3])
 y: array([ 3.4,  6.3])

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy