Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

random.sample() docs unclear on k < len(population) #59470

Closed
roysmith mannequin opened this issue Jul 6, 2012 · 6 comments
Closed

random.sample() docs unclear on k < len(population) #59470

roysmith mannequin opened this issue Jul 6, 2012 · 6 comments
Assignees
Labels
docs Documentation in the Doc dir type-feature A feature request or enhancement

Comments

@roysmith
Copy link
Mannequin

roysmith mannequin commented Jul 6, 2012

BPO 15265
Nosy @rhettinger
Files
  • issue15265-fix-docs.patch
  • issue15265-fix-docs-update.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/rhettinger'
    closed_at = <Date 2012-07-08.23:02:27.161>
    created_at = <Date 2012-07-06.17:50:44.677>
    labels = ['type-feature', 'docs']
    title = 'random.sample() docs unclear on k < len(population)'
    updated_at = <Date 2012-07-08.23:02:27.160>
    user = 'https://bugs.python.org/roysmith'

    bugs.python.org fields:

    activity = <Date 2012-07-08.23:02:27.160>
    actor = 'rhettinger'
    assignee = 'rhettinger'
    closed = True
    closed_date = <Date 2012-07-08.23:02:27.161>
    closer = 'rhettinger'
    components = ['Documentation']
    creation = <Date 2012-07-06.17:50:44.677>
    creator = 'roysmith'
    dependencies = []
    files = ['26285', '26296']
    hgrepos = []
    issue_num = 15265
    keywords = ['patch']
    message_count = 6.0
    messages = ['164742', '164803', '164843', '164845', '165043', '165044']
    nosy_count = 5.0
    nosy_names = ['rhettinger', 'roysmith', 'docs@python', 'python-dev', 'kmox83']
    pr_nums = []
    priority = 'low'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue15265'
    versions = []

    @roysmith
    Copy link
    Mannequin Author

    roysmith mannequin commented Jul 6, 2012

    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().

    @roysmith roysmith mannequin assigned docspython Jul 6, 2012
    @roysmith roysmith mannequin added docs Documentation in the Doc dir type-feature A feature request or enhancement labels Jul 6, 2012
    @rhettinger rhettinger assigned rhettinger and unassigned docspython Jul 7, 2012
    @kmox83
    Copy link
    Mannequin

    kmox83 mannequin commented Jul 7, 2012

    Added the related line to the documentation describing when the exception is raised.

    @roysmith
    Copy link
    Mannequin Author

    roysmith mannequin commented Jul 7, 2012

    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`.

    @kmox83
    Copy link
    Mannequin

    kmox83 mannequin commented Jul 7, 2012

    Ok, I have updated the patch

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jul 8, 2012

    New changeset 72174d8af3ba by Raymond Hettinger in branch 'default':
    bpo-15265: document the exception raised for invalid sample sizes.
    http://hg.python.org/cpython/rev/72174d8af3ba

    @rhettinger
    Copy link
    Contributor

    Thanks, I've added a note.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    docs Documentation in the Doc dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant