Issue 15265: random.sample() docs unclear on k < len(population) (original) (raw)

Created on 2012-07-06 17:50 by roysmith, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
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. http://hg.python.org/cpython/rev/72174d8af3ba
msg165044 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2012-07-08 23:02
Thanks, I've added a note.
History
Date User Action Args
2022-04-11 14:57:32 admin set github: 59470
2012-07-08 23:02:27 rhettinger set status: open -> closedresolution: fixedmessages: +
2012-07-08 23:02:01 python-dev set nosy: + python-devmessages: +
2012-07-07 13:45:13 kmox83 set files: + issue15265-fix-docs-update.patchmessages: +
2012-07-07 13:38:20 roysmith set messages: +
2012-07-07 10:13:59 kmox83 set files: + issue15265-fix-docs.patchnosy: + kmox83messages: + keywords: + patch
2012-07-07 06:13:06 rhettinger set priority: normal -> lowassignee: docs@python -> rhettinger
2012-07-06 20:14:23 pitrou set nosy: + rhettinger
2012-07-06 17:50:44 roysmith create