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

ERROR: test_stats.test_chisquare_masked_arrays #5426

Closed
jlec opened this issue Oct 25, 2015 · 20 comments

Comments

@jlec
Copy link

@jlec jlec commented Oct 25, 2015

======================================================================
ERROR: test_stats.test_chisquare_masked_arrays
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib64/python3.4/site-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/var/tmp/portage/sci-libs/scipy-0.16.1/work/scipy-0.16.1-python3_4/build/test/lib/scipy/stats/tests/test_stats.py", line 1898, in test_chisquare_masked_arrays
    chisq, p = stats.chisquare(np.ma.array([]))
  File "/var/tmp/portage/sci-libs/scipy-0.16.1/work/scipy-0.16.1-python3_4/build/test/lib/scipy/stats/stats.py", line 4174, in chisquare
    lambda_="pearson")
  File "/var/tmp/portage/sci-libs/scipy-0.16.1/work/scipy-0.16.1-python3_4/build/test/lib/scipy/stats/stats.py", line 4030, in power_divergence
    f_exp = np.atleast_1d(f_obs.mean(axis=axis))
  File "/usr/lib64/python3.4/site-packages/numpy/ma/core.py", line 4987, in mean
    result = super(MaskedArray, self).mean(axis=axis, dtype=dtype)
  File "/usr/lib64/python3.4/site-packages/numpy/core/_methods.py", line 59, in _mean
    warnings.warn("Mean of empty slice.", RuntimeWarning)
RuntimeWarning: Mean of empty slice.

----------------------------------------------------------------------

python-3.4
scipy-0.16.1
numpy-1.10.1

@rgommers

This comment has been minimized.

Copy link
Member

@rgommers rgommers commented Oct 25, 2015

Hmm, forgot to silence this one apparently. It should be just a warning not an error though. That'll be fixed in numpy 1.10.2. Either way, we need to fix this warning if it's still present in master.

@rgommers

This comment has been minimized.

Copy link
Member

@rgommers rgommers commented Oct 25, 2015

Note that the warning will only be visible in Python >= 3.4 (I think), not in 2.7.

@rgommers

This comment has been minimized.

Copy link
Member

@rgommers rgommers commented Oct 25, 2015

So if someone wants to tackle this:

  • check that it's still present on the master branch
  • silence the warning with warnings.catch_warnings (search for other usages in the stats test suite for an example if needed)
@person142

This comment has been minimized.

Copy link
Member

@person142 person142 commented Oct 28, 2015

This has been fixed in master. Running nosetests doesn't show the error anymore, and the snippet that caused problems in test_stats.test_chisquare_masked_arrays now reads

with warnings.catch_warnings(record=True):
    chisq, p = stats.chisquare(np.ma.array([]))

So I think the issue can be closed.

@ev-br

This comment has been minimized.

Copy link
Member

@ev-br ev-br commented Oct 28, 2015

Thanks for checking it @person142 !

@ev-br ev-br closed this Oct 28, 2015
@jlec

This comment has been minimized.

Copy link
Author

@jlec jlec commented Oct 28, 2015

@person142 Could you point me to the actual commit so that I can backport a patch?

@person142

This comment has been minimized.

Copy link
Member

@person142 person142 commented Oct 29, 2015

@jlec: looks like it was 02ea47.

@jlec

This comment has been minimized.

Copy link
Author

@jlec jlec commented Oct 29, 2015

@person142 @ev-br I still see this error with latest HEAD (@ 6f205e9)

@ev-br

This comment has been minimized.

Copy link
Member

@ev-br ev-br commented Oct 29, 2015

OK, reopening then

@ev-br ev-br reopened this Oct 29, 2015
@jlec

This comment has been minimized.

Copy link
Author

@jlec jlec commented Oct 29, 2015

actually 02ea478 is already included in 0.16.1

@person142

This comment has been minimized.

Copy link
Member

@person142 person142 commented Oct 30, 2015

Well shoot, I'm confused. I'm running this from inside a fresh virtualenv:

$ python -c "import sys, numpy, scipy; print(sys.version_info); print(numpy.__version__); print(scipy.__version__)"
sys.version_info(major=3, minor=4, micro=3, releaselevel='final', serial=0)
1.10.1
0.16.1
$ nosetests test_stats.py:test_chisquare_masked_arrays
.
----------------------------------------------------------------------
Ran 1 test in 0.017s

OK

Also ran it with

python -m "nose" test_stats.py

to make sure it wasn't somehow using the system nosetests binary; got the same result.

I'm clearly doing something wrong, but I'm not sure what it is yet. Probably going to be woefully embarrassing when I find out.

@jlec

This comment has been minimized.

Copy link
Author

@jlec jlec commented Oct 30, 2015

Both
$ nosetests test_stats.py:test_chisquare_masked_arrays and python -m "nose" test_stats.py
work here.

The way we are testing is running the following code

import scipy, sys
r = scipy.test('fast',verbose=2)
 sys.exit(0 if r.wasSuccessful() else 1)

We are using the package provided from pypi which doesn't include the runtests.py. Is this the correct way to test it or would you suggest a better syntax?

@person142

This comment has been minimized.

Copy link
Member

@person142 person142 commented Oct 30, 2015

So scipy is using numpy.testing.Tester.test, see

https://docs.scipy.org/doc/numpy/reference/generated/numpy.testing.Tester.test.html

I think the right thing to do here would be

r = scipy.test('fast', verbose=2, raise_warnings='release')

which will silence the errors that came from warnings. But perhaps someone wiser than me (@rgommers, @ev-br) would say differently?

@rgommers

This comment has been minimized.

Copy link
Member

@rgommers rgommers commented Oct 30, 2015

The way @jlec runs the tests is also perfectly valid. scipy.test() is recommended actually, IIRC because it loads the nose plugin for KwownfailureIf while nosetests scipy doesn't.

@person142 that's a way to silence the warning, but we'd like to fix it instead of silence it. The reason that numpy even has a raise_warnings='develop' is so we notice this test noise and turn it into errors so TravisCI turns red.

@rgommers

This comment has been minimized.

Copy link
Member

@rgommers rgommers commented Oct 30, 2015

I'm a bit puzzled about the different behavior though. I'll see later if I can reproduce.

@jlec

This comment has been minimized.

Copy link
Author

@jlec jlec commented Oct 31, 2015

Using

r = scipy.test('fast', verbose=2, raise_warnings='release')

let's the testsuite succeed.

jlec added a commit to gentoo/gentoo that referenced this issue Oct 31, 2015
Github: scipy/scipy#5426

Package-Manager: portage-2.2.23
Signed-off-by: Justin Lecher <jlec@gentoo.org>
@rgommers

This comment has been minimized.

Copy link
Member

@rgommers rgommers commented Oct 31, 2015

Okay, reproduced this. It turns into an error because the test itself doesn't filter the warning and there was the bug with raise_warnings='develop' in numpy 1.10.1. So this'll go away for numpy 1.10.2, but we also need to fix the tests (there are more actually). PR coming soon.

@rgommers

This comment has been minimized.

Copy link
Member

@rgommers rgommers commented Oct 31, 2015

Still odd that it's Python 3.4 (or 3.x) specific. IIRC something changed in the warnings module, but I can't remember what.

@rgommers

This comment has been minimized.

Copy link
Member

@rgommers rgommers commented Oct 31, 2015

okay, should be fixed by gh-5445. If it's Python and Numpy version specific, then the chance that it's in our build matrix on TravisCI is not that high.....

@rgommers

This comment has been minimized.

Copy link
Member

@rgommers rgommers commented Oct 31, 2015

@jlec now I see what you meant - running the tests with raise_warnings='release' in a Gentoo build seems perfectly valid as a workaround/fix.

@ev-br ev-br closed this in #5445 Oct 31, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.