gh-121977: Add tips for handling unhashable data (#122075)

This commit is contained in:
Raymond Hettinger 2024-07-21 00:53:26 -05:00 committed by GitHub
parent c4c7097e64
commit ebc18abbf3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 0 deletions

View File

@ -485,6 +485,12 @@ However, for reading convenience, most of the examples show sorted sequences.
>>> mode(["red", "blue", "blue", "red", "green", "red", "red"])
'red'
Only hashable inputs are supported. To handle type :class:`set`,
consider casting to :class:`frozenset`. To handle type :class:`list`,
consider casting to :class:`tuple`. For mixed or nested inputs, consider
using this slower quadratic algorithm that only depends on equality tests:
``max(data, key=data.count)``.
.. versionchanged:: 3.8
Now handles multimodal datasets by returning the first mode encountered.
Formerly, it raised :exc:`StatisticsError` when more than one mode was