[Python-bugs-list] [ python-Bugs-801342 ] Bug (documentation or real, your choice) in random.sample.

SourceForge.net noreply at sourceforge.net
Fri Sep 5 14:21:15 EDT 2003


Bugs item #801342, was opened at 2003-09-05 16:21
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=801342&group_id=5470

Category: Python Library
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Jeremy Fincher (jemfinch)
Assigned to: Nobody/Anonymous (nobody)
Summary: Bug (documentation or real, your choice) in random.sample.

Initial Comment:
First, the bug: 
 
>>> s 
Set([1, 2, 4, 5, 6, 34]) 
>>> random.sample(s, 1) 
Traceback (most recent call last): 
  File "<stdin>", line 1, in ? 
  File "/usr/lib/python2.3/random.py", line 266, in 
sample 
    result[i] = selected[j] = population[j] 
TypeError: unindexable object 
 
The interesting thing is this: 
 
>>> random.sample(s, 4) 
[6, 4, 2, 5] 
 
So it works when the sample size is sufficiently 
large, but not when it's small relative to the size of 
the population. 
 
Now, the documentation: 
 
>>> print random.sample.__doc__ 
Chooses k unique random elements from a 
population sequence. 
<snip> 
 
I think either the documentation needs to be 
changed to indicate that the sequence must be 
indexable, or the behavior when the sample is 
small relative to the population should be changed 
to allow non-indexable sequences. 

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=801342&group_id=5470



More information about the Python-bugs-list mailing list