On Sun, Dec 29, 2019, 9:23 PM Andrew Barnert > Here it is. I could save a line by not using the 'else'. > > def total_order(x): > if is_nan(x): > return (math.copysign(1, x), x) > else: > return (0, x) > > > This doesn’t give you IEEE total order. Under what circumstances would you > prefer this to, say, Decimal.compare_total, which does? >
How does this differ from IEEE? I'm not being rhetorical, I really thought that was their order. But I haven't looked carefully. median_employee = statistics.median((e.salary, e) for e in employees)[1] > > By the same argument, nothing actually needs a key function because you > can always decorate-sort-undecorate. And yet, key functions are useful in > all kinds of places. > It's a balance, I think. `key_fn=` feels much too "heavy" for users of statistics module. Handling NaNs one way or the other is the 95% concern. And for the 5%, DSU covers it. DSU or key_fn is "advanced users." Beginners won't understands either, but will grok nan messing up their answers. Experts will have no difficulty with DSU. The built-in sorted() has a different balance since it is more generic in functionality. I wrote privately that I thought having a statistics._median() have a key_fn could make sense. Regular statistics.median() could utilize that, but the public function should have a less confusing API. I don't care about enum vs string. Pandas and NumPy use strings, but they are older than the enum module.
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/VBGT7WBXFXJN2MQRWABCSUUEC5ECTE5V/ Code of Conduct: http://python.org/psf/codeofconduct/