Raymond Hettinger <raymond.hettin...@gmail.com> added the comment:

Normally early-out behaviors are allowed to skip any checks for subsequent 
inputs (for example, the any() and all() builtins stop consuming inputs one a 
final value is found).

However, that reasoning might not apply to a zero input for harmonic_mean().  
Technically, the definition of harmonic mean doesn't allow for a zero input 
value at all (accordingly, MS Excel gives an error for a zero input).  
Presumably, the reason that Python's harmonic_mean() returns zero is so that 
the function degrades gracefully as one of the inputs gets closer to zero.

Options at this point:

* Just document that there is an early-out for zero.

* Stick with the strategy of treating zero as if it were just a very, very 
small positive input.  The would imply that all of the inputs should be 
considered and that TypeErrors or StatisticErrors should be raised for later 
data points (though I'm unclear what this world view implies when the inputs 
have both a zero and a positive infinity).

* Treat a zero input as an error.  This matches the usual specification of 
harmonic mean being defined only for non-negative real inputs.

----------
nosy: +mark.dickinson, tim.peters

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue38382>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to