This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients Windson Yang, francismb, rhettinger, steven.daprano
Date 2019-02-22.17:48:56
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1550857736.48.0.737242231468.issue35892@roundup.psfhosted.org>
In-reply-to
Content
> 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
History
Date User Action Args
2019-02-22 17:48:56rhettingersetrecipients: + rhettinger, steven.daprano, francismb, Windson Yang
2019-02-22 17:48:56rhettingersetmessageid: <1550857736.48.0.737242231468.issue35892@roundup.psfhosted.org>
2019-02-22 17:48:56rhettingerlinkissue35892 messages
2019-02-22 17:48:56rhettingercreate