Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scipy.stats.kappa4(h,k) raise a ValueError for positive integer values of h and k #7416

Closed
pvanmulbregt opened this issue May 18, 2017 · 1 comment · Fixed by #7420
Closed
Labels
defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.stats
Milestone

Comments

@pvanmulbregt
Copy link
Contributor

scipy.stats.kappa4(1, 2) raises a ValueError: "Integers to negative integer powers are not allowed."

scipy.stats.kappa4() requires two shape parameters, h and k.
If h and k are both positive integers, then the constructor fails inside kappa4_gen._argcheck(self, h, k), as the function f0(h, k) attempts to raise h, an integer, to a negative power (-k).

If h is a float with the same value, the call succeeds. Or If k is a float with the same value, the call succeeds.

>>> scipy.stats.kappa4(h=1, k=2)   # Fails, raises ValueError
>>> scipy.stats.kappa4(h=1.0, k=2)  # Succeeds
<scipy.stats._distn_infrastructure.rv_frozen object at 0x111b3ce48>
>>> scipy.stats.kappa4(h=1, k=2.0)  # Succeeds
<scipy.stats._distn_infrastructure.rv_frozen object at 0x111b3e160>

Reproducing code example:

import scipy.stats
scipy.stats.kappa4(1, 2)

Error message:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/Paul/anaconda/lib/python3.6/site-packages/scipy/stats/_distn_infrastructure.py", line 772, in __call__
    return self.freeze(*args, **kwds)
  File "/Users/Paul/anaconda/lib/python3.6/site-packages/scipy/stats/_distn_infrastructure.py", line 769, in freeze
    return rv_frozen(self, *args, **kwds)
  File "/Users/Paul/anaconda/lib/python3.6/site-packages/scipy/stats/_distn_infrastructure.py", line 438, in __init__
    self.dist._argcheck(*shapes)
  File "/Users/Paul/anaconda/lib/python3.6/site-packages/scipy/stats/_continuous_distns.py", line 3477, in _argcheck
    default=np.nan)
  File "/Users/Paul/anaconda/lib/python3.6/site-packages/scipy/_lib/_util.py", line 98, in _lazyselect
    np.place(out, cond, func(*temp))
  File "/Users/Paul/anaconda/lib/python3.6/site-packages/scipy/stats/_continuous_distns.py", line 3461, in f0
    return (1.0 - h**(-k))/k
ValueError: Integers to negative integer powers are not allowed.

Scipy/Numpy/Python version information:

0.19.0 1.12.1 sys.version_info(major=3, minor=6, micro=1, releaselevel='final', serial=0)
ev-br added a commit to ev-br/scipy that referenced this issue May 20, 2017
Using integer h and k fails in numpy 1.12 and above because
of the np.power(integer, negative integer) change.

fixes scipygh-7416
@ev-br
Copy link
Member

ev-br commented May 20, 2017

Thanks for the report.
This can be annoying indeed. gh-7420 should fix it.

@ev-br ev-br added scipy.stats defect A clear bug or issue that prevents SciPy from being installed or used as expected labels May 20, 2017
@ev-br ev-br added this to the 1.0 milestone Jun 14, 2017
rgommers pushed a commit to rgommers/scipy that referenced this issue Jun 18, 2017
Using integer h and k fails in numpy 1.12 and above because
of the np.power(integer, negative integer) change.

fixes scipygh-7416

(cherry picked from commit 83ef37b)

Backport of scipygh-7420
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.stats
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants