Skip to content

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

Closed

Description

@roysmith
mannequin
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 = []

    Activity

    1. roysmith commented on Jul 6, 2012

      roysmithmannequin
      MannequinAuthor

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

    2. added
      docsDocumentation in the Doc dir
      type-featureA feature request or enhancement
      on Jul 6, 2012
    3. kmox83 commented on Jul 7, 2012

      kmox83mannequin
      Mannequin

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

    4. roysmith commented on Jul 7, 2012

      roysmithmannequin
      MannequinAuthor

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

    5. kmox83 commented on Jul 7, 2012

      kmox83mannequin
      Mannequin

      Ok, I have updated the patch

    6. python-dev commented on Jul 8, 2012

      python-devmannequin
      Mannequin

      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

    7. rhettinger commented on Jul 8, 2012

      @rhettinger
      Contributor

      Thanks, I've added a note.

    8. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    docsDocumentation in the Doc dirtype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions