Skip to content

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

@sporksmith

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?)

Metadata

Metadata

Assignees

No one assigned

    Labels

    X-bugType: bug report

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions