Title: random.sample() docs unclear on k < len(population)
Type: enhancement Stage:
Components: Documentation Versions:
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: docs@python, kmox83, python-dev, rhettinger, roysmith
Priority: low Keywords: patch

Created on 2012-07-06 17:50 by roysmith, last changed 2012-07-08 23:02 by rhettinger. This issue is now closed.

File name Uploaded Description Edit
issue15265-fix-docs.patch kmox83, 2012-07-07 10:13 review
issue15265-fix-docs-update.patch kmox83, 2012-07-07 13:45 review
Messages (6)
msg164742 - (view) Author: Roy Smith (roysmith) Date: 2012-07-06 17:50
The docs don't say what happens if you call random.sample() with a population smaller than k.  Experimentally, it raises ValueError, but this should be documented.

I would have guessed it would return IndexError, by analogy to random.choice().
msg164803 - (view) Author: Eugenio Minardi (kmox83) Date: 2012-07-07 10:13
Added the related line to the documentation describing when the exception is raised.
msg164843 - (view) Author: Roy Smith (roysmith) Date: 2012-07-07 13:38
The docs describe population as a "sequence".  Your patch describes it as a "list".  I would go with:

If *len(population)* is less than *k*, raises :exc:`ValueError`.
msg164845 - (view) Author: Eugenio Minardi (kmox83) Date: 2012-07-07 13:45
Ok, I have updated the patch
msg165043 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-07-08 23:02
New changeset 72174d8af3ba by Raymond Hettinger in branch 'default':
Issue 15265: document the exception raised for invalid sample sizes.
msg165044 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2012-07-08 23:02
Thanks, I've added a note.
Date User Action Args
2012-07-08 23:02:27rhettingersetstatus: open -> closed
resolution: fixed
messages: + msg165044
2012-07-08 23:02:01python-devsetnosy: + python-dev
messages: + msg165043
2012-07-07 13:45:13kmox83setfiles: + issue15265-fix-docs-update.patch

messages: + msg164845
2012-07-07 13:38:20roysmithsetmessages: + msg164843
2012-07-07 10:13:59kmox83setfiles: + issue15265-fix-docs.patch

nosy: + kmox83
messages: + msg164803

keywords: + patch
2012-07-07 06:13:06rhettingersetpriority: normal -> low
assignee: docs@python -> rhettinger
2012-07-06 20:14:23pitrousetnosy: + rhettinger
2012-07-06 17:50:44roysmithcreate