[Python-ideas] thoughts on the new 3.4 statistics module
Oleg Broytman
phd at phdru.name
Tue Dec 24 20:13:09 CET 2013
Hi!
On Sat, Dec 21, 2013 at 02:29:14PM -0800, Wolfgang <wolfgang.maier at biologie.uni-freiburg.de> wrote:
> First: I am not entirely convinced by when the module raises Errors. In
> some places its undoubtedly justified to raise StatisticsError (like when
> empty sequences are passed to mean()).
> On the other hand, should there really be an error, when for example no
> unique value for the mode can be found?
> Effectively, that would force users to guard every (!) call to the function
> with try/except.
Not necessary. The user of the library can combine a few calls in a
function/method and catch one exception for the entire calculation. Or
catch it even higher up the stack.
> In my opinion, a better choice would be to return
> float('nan') or even better a module-specific object (call it Undefined or
> something) that one can check for.
With such special values the user must check every return value. What
is the advantage over catching exceptions?
Oleg.
--
Oleg Broytman http://phdru.name/ phd at phdru.name
Programmers don't die, they just GOSUB without RETURN.
More information about the Python-ideas
mailing list