[Numpy-discussion] Warnings in numpy.ma.test()

Pierre GM pgmdevlist@gmail....
Wed Mar 17 16:20:27 CDT 2010

On Mar 17, 2010, at 11:09 AM, Bruce Southey wrote:
> On 03/17/2010 01:07 AM, Pierre GM wrote:
>> All,
>> As you're probably aware, the current test suite for numpy.ma raises some nagging warnings such as "invalid value in ...". These warnings are only issued when a standard numpy ufunc (eg., np.sqrt) is called on a MaskedArray, instead of its numpy.ma (eg., np.ma.sqrt) equivalent. The reason is that the masked versions of the ufuncs temporarily set the numpy error status to 'ignore' before the operation takes place, and reset the status to its original value.
> Perhaps naive question, what is really being tested here?
> That is, it appears that you are testing both the generation of the 
> invalid values and function. So if the generation fails, then the 
> function will also fail. However, the test for the generation of invalid 
> values  should be elsewhere so you have to assume that the generation of 
> values will work correctly.

That's not really the point here. The issue is that when numpy ufuncs are called on a MaskedArray, a warning or an exception is raised when an invalid is met. With the numpy.ma version of those functions, the error is trapped and processed. Of course, using the numpy.ma version of the ufuncs is the right way to go

> I think that you should be only testing that the specific function 
> passes the test. Why not just use 'invalid' values like np.inf directly?
> For example, in numpy/ma/tests/test_core.py
> We have this test:
>     def test_fix_invalid(self):
>         "Checks fix_invalid."
>         data = masked_array(np.sqrt([-1., 0., 1.]), mask=[0, 0, 1])
>         data_fixed = fix_invalid(data)
> If that is to test that fix_invalid Why not create the data array as:
> data = masked_array([np.inf, 0., 1.]), mask=[0, 0, 1])

Sure, that's nicer. But once again, that's not really the core of the issue.

More information about the NumPy-Discussion mailing list