Skip to content

statistics.mode fails for unhashable data #121977

@MarkRotchell

Description

@MarkRotchell

Bug report

Bug description:

statistics.mode uses collections.Counter so only works for data that are hashable

from statistics import mode
mode([{1,2},{1,2},{3}])

raisesTypeError: unhashable type: 'set'

Same issue with multimode.

This limitation is not mentioned in the docs or the docstring.

Potential solutions:

  1. Add the fact that the function doesn't work on unhashable types to the documentation, and raise a StatisticsError if the user provides unhashable data
  2. Come up with a separate algorithm for handling unhashable data. Would be interested to hear ideas on the appropriate algorithm.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Windows

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions