[issue25177] OverflowError in statistics.mean when summing large floats

Mark Dickinson report at bugs.python.org
Tue Oct 20 02:44:40 EDT 2015


Mark Dickinson added the comment:

> I strongly suspect that moving from float to Fraction-based ratios is going to kill performance in the common case

The existing code already converts each of the input items to Fraction; the only difference is that the old code converts the sum of those Fractions to float (or whatever the target type is) *before* dividing by the count, while the new code performs the sum/count division in Fraction-land, and only *then* converts to float.  That is, it's the difference between "float(exact_sum) / count" and "float(exact_sum / count)".

IOW, the performance is already dead.  Or rather, it's just resting: IIUC, the module design prioritises correctness over speed.  I'm sure Steven would be open to suggestions for faster algorithms that maintain the current accuracy.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue25177>
_______________________________________


More information about the Python-bugs-list mailing list