Treatment of NANs in the statistics module

Steven D'Aprano steve+comp.lang.python at pearwood.info
Fri Mar 16 19:16:48 EDT 2018


The bug tracker currently has a discussion of a bug in the median(), 
median_low() and median_high() functions that they wrongly compute the 
medians in the face of NANs in the data:

https://bugs.python.org/issue33084

I would like to ask people how they would prefer to handle this issue:

(1) Put the responsibility on the caller to strip NANs from their data. 
If there is a NAN in your data, the result of calling median() is 
implementation-defined. This is the current behaviour, and is likely to 
be the fastest.

(2) Return a NAN.

(3) Raise an exception.

(4) median() should strip out NANs.

(5) All of the above, selected by the caller. (In which case, which would 
you prefer as the default?)


Thank you.




-- 
Steve




More information about the Python-list mailing list