Tracing Python warnings/errors to a line number in numpy and scipy Tracing Python warnings/errors to a line number in numpy and scipy numpy numpy

Tracing Python warnings/errors to a line number in numpy and scipy


Putting np.seterr(invalid='raise') in your code (before the errant log call)will cause numpy to raise an exception instead of issuing a warning.That will give you a traceback error message and tell you the line Python was executing when the error occurred.


If you have access to the numpy source, you should be able to find the line that prints that warning (using grep, etc) and edit the corresponding file to force an error (using an assertion, for example) when an invalid value is passed. That will give you a stack trace pointing to the place in your code that called log with the improper value.

I had a brief look in my numpy source, and couldn't find anything that matches the warning you described though (my version of numpy is older than yours, though).

>>> import numpy>>> numpy.log(0)-inf>>> numpy.__version__'1.3.0'

Is it possible that you're calling some other log function that isn't in numpy? For example, here is one that actually throws an exception when given invalid input.

>>> import math>>> math.log(0)Traceback (most recent call last):  File "<stdin>", line 1, in <module>ValueError: math domain error