Skip to content

doc-comment for IndexedRandom::choose_weighted is wrong for empty sequences #1783

Closed

Description

@sporksmith

The doc-comment for IndexedRandom::choose_weighted says:

Returns None if and only if self.is_empty()

but the function doesn't return an Option; it returns a Result. In particular it seems to return WeightError::InvalidInput if the sequence is empty.

I notice that choose_weighted_iter also is documented to return None in this case despite not returning an Option, but haven't tested the actual behavior. (Probably the same error? Maybe an empty iterator?)

Activity

  1. added
    X-bug
    on May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    X-bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions