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.

classification
Title: some trable with max when np.nan is in the first of a list
Type: Stage: resolved
Components: Tests Versions: Python 3.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: 1147945735@qq.com, mark.dickinson, xtreak
Priority: normal Keywords:

Created on 2019-09-16 06:36 by 1147945735@qq.com, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (4)
msg352513 - (view) Author: 薛定谔的喵 (1147945735@qq.com) Date: 2019-09-16 06:36
max([5.0,np.nan])  >>>  5.0
max([np.nan,5.0])  >>>  nan
msg352515 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2019-09-16 06:50
I think it's more about how np.nan eq is implemented and not a bug in Python. I find this answer to be a good explanation https://stackoverflow.com/a/47788524/2610955
msg352517 - (view) Author: 薛定谔的喵 (1147945735@qq.com) Date: 2019-09-16 07:01
thanks .
msg352518 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2019-09-16 07:03
Right, `max` can only give meaningful results when presented with elements that belong to a totally-ordered collection. Unfortunately, floats-including-nan is not such a collection (though floats-excluding-nan *is*, provided we ignore wrinkles with positive and negative zero).

Here's the source of the issue:

Python 3.7.4 (default, Sep  7 2019, 19:52:29) 
[Clang 10.0.1 (clang-1001.0.46.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> 5.0 < np.nan
False
>>> np.nan < 5.0
False
History
Date User Action Args
2022-04-11 14:59:20adminsetgithub: 82362
2019-09-16 07:18:13mark.dickinsonsetstatus: open -> closed
resolution: not a bug
stage: resolved
2019-09-16 07:03:00mark.dickinsonsetstatus: closed -> open

nosy: + mark.dickinson
messages: + msg352518

resolution: third party -> (no value)
stage: resolved -> (no value)
2019-09-16 07:01:461147945735@qq.comsetstatus: open -> closed
resolution: third party
messages: + msg352517

stage: resolved
2019-09-16 06:50:34xtreaksetnosy: + xtreak
messages: + msg352515
2019-09-16 06:36:241147945735@qq.comcreate