14

I am getting

C:\Anaconda\lib\site-packages\numpy\core\_methods.py:59: RuntimeWarning: Mean of empty slice.
    warnings.warn("Mean of empty slice.", RuntimeWarning)

when I run a code I wrote. This is a large codebase. The problem is, I do not see where in my code this warning was fired.

I would rather have this as an error (e.g. an exception), so that I can see where this was generated in my code.

Is it possible to have exceptions instead of warnings?

Note: I solved my problem debugging line by line. But the question still stands.

O. Altun
  • 685
  • 7
  • 20

2 Answers2

15

Setting

numpy.seterr(all='raise')

should do the trick. You should probably check out the details though.

fbence
  • 2,025
  • 2
  • 19
  • 42
5
import warnings

warnings.filterwarnings('error', "Mean of empty slice.")

# ... Your code here.

See the documentation of the warnings module for more details.

Robert Kern
  • 13,118
  • 3
  • 35
  • 32