votes up 1

n is not integral: (_n)

github stars 8546
Exception Class:

Raise code

    it = np.nditer([n, x, cdf, None],
                   op_dtypes=[None, np.float64, np.bool_, np.float64])
    for _n, _x, _cdf, z in it:
        if np.isnan(_n):
            z[...] = _n
        if int(_n) != _n:
            raise ValueError(f'n is not integral: {_n}')
        z[...] = _kolmogn(int(_n), _x, cdf=_cdf)
    result = it.operands[-1]
    return result

def kolmognp(n, x):
    """Computes the PDF for the two-sided Kolmogorov-Smirnov distribution. """

Ways to fix

votes up 1 votes down

The value of the parameter n should be an integer type.

How to reproduce it:

$ pipenv install scipy

$ pipenv shell

from scipy.stats._ksstats import kolmogn
res = kolmogn(3.9,3) # the first argument here causes the error

ValueError Traceback (most recent call last)
<ipython-input-7-740e811e37aa> in <module>()  1 from scipy.stats._ksstats import kolmogn  2  ----> 3 res = kolmogn(3.9,3)  4 print(res) 
/usr/local/lib/python3.7/dist-packages/scipy/stats/ in kolmogn(n, x, cdf)  530 continue  531 if int(_n) != _n: --> 532 raise ValueError(f'n is not integral: {_n}')  533 z[...] = _kolmogn(int(_n), _x, cdf=_cdf)  534 result = it.operands[-1] 
ValueError: n is not integral: 3.9

Fixed version of the sample code:

from scipy.stats._ksstats import kolmogn

res = kolmogn(3,3)
Oct 13, 2021 kellemnegasi answer
kellemnegasi 13.5k

Add a possible fix

Please authorize to post fix