[Numpy-discussion] RuntimeWarning raised in the wrong line

Benjamin Root ben.root at ou.edu
Wed Nov 20 09:34:52 EST 2013


On Wed, Nov 20, 2013 at 9:09 AM, Daπid <davidmenhur at gmail.com> wrote:

> I have the following code, operating on some arrays.
>
> pen = 1 - (real_sum[int(i1 + t)]) / (absolute[int(i1 + t)])
> if np.isnan(pen):
>                 pen = 0.0
>
> I know that, sometimes, real_sum and absolute are 0 at the designated
> point, so I should get a RuntimeWarning. But, the warning is puzzling:
>
> RuntimeWarning: invalid value encountered in double_scalars
>   pen = 0.0
>
> Is the warning actually being raised at that point? Or can I not really
> trust the line reported by the warning? I have tried to replicate it in
> interactive terminal, but without luck, I always get it in the previous
> line.
>
>
> I am using Python 2.7 and Numpy 1.8.0.
>
>
> /David.
>
>
This can sometimes happen in very weird edge cases of development
workflows. Essentially, if one edits the source code while the module is
still loaded in the python session, the line numbers recorded in the *.pyc
files diverge from the source code. The warning that is emitted checks the
source code at that time to print out the relevant line. Maybe that might
explain what is happening here?

Ben Root
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20131120/5b7f0050/attachment.html>


More information about the NumPy-Discussion mailing list