Raymond Hettinger <[email protected]> added the comment:
> shouldn't be "mode" at some point be replaced by "multimode" ?
No. The signature is completely incompatible with the existing mode() function.
Like MS Excel which has two functions, MODE.SGNL and MODE.MULT, we should also
have two functions, each with a clean signature and with running speed that is
optimal for the desired result:
mode(data: Iterable) -> object
Returns a single value
If multiple modes found, return first encountered
Raises StatisticsError for an empty input
Fast O(n), single pass, doesn't keep all data in memory
multimode(data: Iterable) -> List[object]
Always returns a list
If multiple modes found, all are returned
Returns an empty list for an empty input
Slow O(n log n), loads all data in memory, full sort
For the first one, I recommend skipping deprecation and just changing the
behavior that usually raises an exception for multiple modes. In its current
form, it likely to create bugs due to uncaught exceptions, and it doesn't
provide any work-around if you do want only one of the modes.
By analogy, consider what would happen if we had a max() function that raised
an exception when there were duplicate maximum values. It would be almost
usable. So, what the real max() actually does is return the first encountered
maximum value:
>>> max(3, 1, 3.0)
3
>>> max(3.0, 1, 3)
3.0
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue35892>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com