[issue37884] Optimize Fraction() and statistics.mean()

Steven D'Aprano report at bugs.python.org
Sun Aug 25 21:42:30 EDT 2019


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

On Sat, Aug 24, 2019 at 10:09:40AM +0000, Serhiy Storchaka wrote:

> Could you please explain what is wrong in adding a helper function 
> which will help to convert different types of numbers to integer ratio 
> correctly?
> 
> Currently you need to write a complex code if you need to convert a 
> general number to integer ratio:

When I first wrote the statistics module, I found that converting to
fractions was a bottleneck. I spent some time tweaking the private 
_exact_ratio() function which is why the code is so hairy.

Being able to simplify and speed up that conversion would be great, and 
I thank Serhiy for looking at this.

But I am concerned about the API, writing a *private* helper function in 
the math module, but then using it in the statistics module as if it 
were public. That will surely encourage people to do the same, and 
before long this private helper will have to be treated as public.

----------

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


More information about the Python-bugs-list mailing list