Python / numpy runtime warning

I have a numpy script sitting on an application server, it is called thousands of times and once in the blue moon. I get a runtime warning:

/usr/local/lib/python2.7/dist-packages/scipy/stats/stats.py:2417: RuntimeWarning: invalid value encountered in double_scalars
r = (r_num / r_den)
  • I don’t know where this is happening.
  • Why is this happening.
  • The consequence that it has in the code, if any. everything passes an eye test and unit test.

But then again, I’m not sure if I’m looking at the right place, because the probability of this acceleration is less than 1%

how can i get python to print the warning location?

+4
source share
3 answers

If you put

np.seterr(all='raise')

script, . script , , .

try...except , , except .


, RuntimeWarning , stats.py, 2417. pearsonr. " , double_scalars" googling, SO,

from scipy.stats.stats import pearsonr

X = [4, 4, 4, 4, 4, 4]
Y = [4, 5, 5, 4, 4, 4]

pearsonr(X, Y)

RuntimeWarning. , pearsonr , ( user3453425) - , - , , , .

pearsonr(X, Y) (nan, 1.0). , , pearson undefined (nan).

+7

:

import warnings
warnings.simplefilter('error')

, , .

+1

:

r = (r_num / r_den)

scipy;

  • linregress pearsonr stats.py.
  • pearsonr mstats_basic.py.

Why: double_scalar is the only one double, not a numpy array. I think that in some calls r_numand / or r_denthere is one (invalid) floating point number. But this is not zero, because zero is not an invalid number, and this will throw a ZeroDivisionError exception. An invalid warning is usually issued when the calculation returns NaN.

+1
source

Source: https://habr.com/ru/post/1533606/


All Articles