[Scipy-tickets] [SciPy] #1507: scipy.stats.rv_generic.rvs Discrete Distribution Rounding Bug

SciPy Trac scipy-tickets@scipy....
Fri Sep 2 14:20:34 CDT 2011

#1507: scipy.stats.rv_generic.rvs Discrete Distribution Rounding Bug
 Reporter:  bestephe     |       Owner:  somebody   
     Type:  defect       |      Status:  new        
 Priority:  normal       |   Milestone:  Unscheduled
Component:  scipy.stats  |     Version:  0.9.0      
 Keywords:               |  
 In the rv_generic class of scipy.stats, starting at line 702 of
 scipy/stats/distributions.py, there is a bug that shows a misunderstanding
 between a discrete distribution and a real (integer) valued distribution.
 The bug causes all random value samples of discrete distributions to be

 Consider, for example, the following snippet of code:

     import scipy.stats

     dist = scipy.stats.rv_discrete(values=([0.25, 0.75], [0.5, 0.5]),

     print dist.rvs()

 As is, the value printed will always be 0, which is not even one of the
 values being sampled from!  Clearly, the value is not actually sampled
 from the distribution.

 The bugfix is simple: delete lines 702-708.  After this fix, the value
 printed in the code sample will be either 0.25 or 0.75, with equal

Ticket URL: <http://projects.scipy.org/scipy/ticket/1507>
SciPy <http://www.scipy.org>
SciPy is open-source software for mathematics, science, and engineering.

More information about the Scipy-tickets mailing list