scipy: BUG: binom.pmf - RuntimeWarning: divide by zero

Describe your issue.

Since installing scipy 1.7.0 with Python 3.10 I get a RuntimeWarning divide by zero encountered counducting the binom.pdf() procedure (see example). Working with scipy 1.6.3 and Python 3.9 I didn’t get this warning. Because of that I pressume a connection with the new C++ _boost library which is now used for tests using the binomial distribution. In detail I found out the difference between the _boost_binom_pdf() and the former _pmf (_discrete_distns.py) is on the one hand the incomplete beta function is used to calculate the binomial coefficient and on the other hand the logarithm of the absolute value of the gamma function is used. This difference seems to lead to the division by zero error in certain constellations.

Reproducing Code Example

from scipy.stats import binom

n = 208
k = 207
p = 0.0003

X = binom.pmf(k, n, p)

Error message

C:\subversion\testrep\07_Envs\Standard\venv_3.10\lib\site-packages\scipy\stats\_discrete_distns.py:67: RuntimeWarning: divide by zero encountered in _binom_pdf
  return _boost._binom_pdf(x, n, p)

SciPy/NumPy/Python version information

1.7.2 1.21.4 sys.version_info(major=3, minor=10, micro=0, releaselevel=‘final’, serial=0)

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 17 (15 by maintainers)

Most upvoted comments

Thanks @mborland!