[issue38382] statistics.harmonic_mean fails to raise error with negative input that follows a 0

Steven D'Aprano report at bugs.python.org
Wed Oct 30 01:21:25 EDT 2019


Steven D'Aprano <steve+python at pearwood.info> added the comment:

Thank you for your comments, but accepting non-floats like Decimal and 
Fraction (and int, of course!) is a hard requirement for the statistics 
module. fmean will naturally convert any data to float for speed, but 
the other means will attempt to keep the original data type if possible, 
so that the mean() of Decimals will be a Decimal, the mean of Fractions 
will be a Fraction, etc.

The median_low and median_high functions don't require numbers at all, 
the data points just need to be ordinal data and support sorting. The 
mode function doesn't even require ordinal data, it can work with 
nominal data. That is part of the definition of median and mode, and 
will not change.

http://intellspot.com/nominal-vs-ordinal-data/

So long as Python support IEEE-754 floating point arithmetic, which is 
the most common standard for floating point, there will be NANs and 
INFs. We should not reject them unnecessarily. You can always pre-filter 
your data before passing it the statistics module.

Why do you object to float INF?

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38382>
_______________________________________


More information about the Python-bugs-list mailing list