mercredi 7 octobre 2015

FAIL: test_nanmedian_all_axis (test_stats.TestNanFunc)

I just installed the newest development version of scipy: 0.17.0.dev0+7dd2b91 and tested it with scipy.test.

I get a single failure:

======================================================================
FAIL: test_nanmedian_all_axis (test_stats.TestNanFunc)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/scipy/stats/tests/test_stats.py", line 242, in test_nanmedian_all_axis
    assert_equal(len(w), 4)
  File "/usr/local/lib/python2.7/dist-packages/numpy/testing/utils.py", line 334, in assert_equal
    raise AssertionError(msg)
AssertionError: 
Items are not equal:
 ACTUAL: 1
 DESIRED: 4

This failure corresponds to the following test function:

class TestNanFunc(TestCase):
    def __init__(self, *args, **kw):
        TestCase.__init__(self, *args, **kw)
        self.X = X.copy()

        self.Xall = X.copy()
        self.Xall[:] = np.nan

        self.Xsome = X.copy()
        self.Xsomet = X.copy()
        self.Xsome[0] = np.nan
        self.Xsomet = self.Xsomet[1:]

    def test_nanmedian_all_axis(self):
        # Check nanmedian when all values are nan.
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter('always')
            m = stats.nanmedian(self.Xall.reshape(3,3), axis=1)
            assert_(np.isnan(m).all())
            assert_equal(len(w), 4)
            assert_(issubclass(w[-1].category, RuntimeWarning))

I was curious about why I was getting this failure, so I carried out the test in the IPython interpreter:

In [1]: import scipy.stats as stats

In [2]: from numpy import array

In [3]: X = array([1,2,3,4,5,6,7,8,9], float)

In [4]: Xall = X.copy()

In [5]: import numpy as np

In [6]: Xall[:] = np.nan

In [7]: import warnings

In [8]: with warnings.catch_warnings(record=True) as w:
    warnings.simplefilter('always')
    m = stats.nanmedian(Xall.reshape(3, 3), axis=1)
    print len(w)
   ....:     
4

As you can see, here I get the length for w expected by the test -- i.e., if I had gotten this value when running the test, it would have passed.

What's going on here? What might I do to uncover the cause of the test failure?

Update

I just re-ran the test, and it passed. Strange! I'm wondering whether the difference is that earlier I did this:

>>> import numpy as np
>>> import scipy
>>> np.test()
>>> scipy.test()

And just now I did this:

>>> import scipy
>>> scipy.test()

Maybe the numpy test suite messes with something that is then used by the scipy test suite?

Aucun commentaire:

Enregistrer un commentaire