Message395506
This is essentially the same issue, but with sorted(): https://bugs.python.org/issue36095
The trouble is that the implementation of min() is roughly equivalent to:
iterable = iter(iterable)
current_min = next(iterable)
for x in iterable:
if x < current_min:
current_min = x
return current_min
NaN < number and number < NaN both return false. Thus including NaNs make floats not totally ordered, so there's no perfect way to sort them or take a max/min. This leads to some unexpected result, as you've identified. So you could say that the real "bug" is in floats more broadly.
This behavior was originally implemented to comply with IEEE 754. Even if that was a mistake, it would be very difficult to change this behavior in case someone's code relies on exactly using this implantation. I also don't like the idea of special-casing the behavior of min/max for floats, since right now the behavior is completely agnostic of the types of the items. |
|
Date |
User |
Action |
Args |
2021-06-10 06:33:24 | Dennis Sweeney | set | recipients:
+ Dennis Sweeney, joel.larose |
2021-06-10 06:33:24 | Dennis Sweeney | set | messageid: <1623306804.08.0.775658430237.issue44370@roundup.psfhosted.org> |
2021-06-10 06:33:24 | Dennis Sweeney | link | issue44370 messages |
2021-06-10 06:33:23 | Dennis Sweeney | create | |
|