8

I am getting warnings like these when running numpy on reasonably large pipeline.

RuntimeWarning: invalid value encountered in true_divide

RuntimeWarning: invalid value encountered in greater

How do I find where they are occurring in the code besides writing dozens of print statements?

Python 2.7 and numpy 1.8.1

1 Answer 1

25

One way is to convert the warnings to errors:

import warnings
warnings.simplefilter('error', RuntimeWarning)

Then the traceback will tell you where the error occurred.

Thanks to @Graham501617 for the following tip:

This can be done without code changes using the python cli:

python -Werror my_script.py

See the Python documentation for more information.

Sign up to request clarification or add additional context in comments.

1 Comment

This can be done without code changes using the python cli: python -Werror my_script.py. docs.python.org/3/using/cmdline.html#cmdoption-W

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.