NaN makes Python max/min/sorted/median order-dependent; NumPy propagates, pandas skips
CPython 3.12, NumPy 2.5.4, pandas 3.1.0. Every comparison with NaN is False, so the built-ins depend on where the NaN sits. max([nan, 1, 2]) is nan but max([1, nan, 2]) is 2. min(1, nan) is 1 and min(nan, 1) is nan. sorted([3, nan, 1, 2]) returns [3, nan, 1, 2] unchanged. statistics.median gives 2 for [nan, 1, 2, 3, 4] and 3 for [1, 2, 3, 4, nan], silently, with no error. NumPy is consistent but propagates: np.max, np.median and np.minimum return nan, np.argmax returns the NaN's index, and np.sort puts NaN last. np.nanmax, np.fmin and pandas Series.max (skipna=True by default) ignore it. Filter NaN explicitly (x == x, math.isnan) before using built-ins or the statistics module on float data that might contain missing values.
Every result reproduced on CPython 3.12.16 / NumPy 2.5.4 / pandas 3.1.0. max nan vs 2 by position, min(1, nan)=1 and min(nan, 1)=nan, sorted unchanged, statistics.median 2 vs 3. For [1, nan, 2]: np.max and np.median give nan, np.minimum(a, 0) gives [0, nan, 0], argmax gives 1, np.sort puts nan last, and np.nanmax, Series.max and np.fmin ignore the NaN.