[issue20499] Rounding errors with statistics.variance

2021-09-09 Thread Steven D'Aprano
Steven D'Aprano added the comment: Regarding the call to sorted that you removed. I just realised that this was buggy! In my testing, I found that there was a consistent speed-up by summing fractions in order of increasing denominators (small denominators first): >>> from fractions import

[issue20499] Rounding errors with statistics.variance

2021-09-09 Thread Steven D'Aprano
Steven D'Aprano added the comment: > rhettinger requested a review from stevendaprano yesterday This is not a complaint Raymond, but you're too quick for me! Your changes look good to me, thank you. -- ___ Python tracker

[issue20499] Rounding errors with statistics.variance

2021-09-08 Thread Raymond Hettinger
Change by Raymond Hettinger : -- assignee: steven.daprano -> rhettinger ___ Python tracker ___ ___ Python-bugs-list mailing list Uns

[issue20499] Rounding errors with statistics.variance

2021-09-08 Thread Raymond Hettinger
Raymond Hettinger added the comment: New changeset 3c30805b58421a1e2aa613052b6d45899f9b1b5d by Raymond Hettinger in branch '3.10': [3.10] bpo-20499: Rounding error in statistics.pvariance (GH-28230) (GH-28248) https://github.com/python/cpython/commit/3c30805b58421a1e2aa613052b6d45899f9b1b5d

[issue20499] Rounding errors with statistics.variance

2021-09-08 Thread Raymond Hettinger
Change by Raymond Hettinger : -- pull_requests: +26669 pull_request: https://github.com/python/cpython/pull/28248 ___ Python tracker ___ ___

[issue20499] Rounding errors with statistics.variance

2021-09-08 Thread Raymond Hettinger
Change by Raymond Hettinger : -- resolution: -> fixed stage: patch review -> resolved status: open -> closed ___ Python tracker ___ ___

[issue20499] Rounding errors with statistics.variance

2021-09-08 Thread Raymond Hettinger
Raymond Hettinger added the comment: New changeset 4a5cccb02bb2254634c0fbb2cbb14e2e7f45e2d5 by Raymond Hettinger in branch 'main': bpo-20499: Rounding error in statistics.pvariance (GH-28230) https://github.com/python/cpython/commit/4a5cccb02bb2254634c0fbb2cbb14e2e7f45e2d5 -- _

[issue20499] Rounding errors with statistics.variance

2021-09-07 Thread Raymond Hettinger
Change by Raymond Hettinger : -- nosy: +rhettinger nosy_count: 4.0 -> 5.0 pull_requests: +26650 stage: -> patch review pull_request: https://github.com/python/cpython/pull/28230 ___ Python tracker __

[issue20499] Rounding errors with statistics.variance

2021-08-20 Thread Irit Katriel
Irit Katriel added the comment: Reproduced on 3.11: >>> statistics.pvariance([0,0,1]) 0.4 >>> statistics.variance([0,0,2]) 1.3335 -- nosy: +iritkatriel versions: +Python 3.10, Python 3.11, Python 3.9 -Python 3.5 ___ Pyt

[issue20499] Rounding errors with statistics.variance

2015-10-19 Thread Steven D'Aprano
Changes by Steven D'Aprano : -- assignee: -> steven.daprano ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: ht

[issue20499] Rounding errors with statistics.variance

2014-10-14 Thread Stefan Krah
Changes by Stefan Krah : -- nosy: -skrah ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.o

[issue20499] Rounding errors with statistics.variance

2014-02-08 Thread Wolfgang Maier
Wolfgang Maier added the comment: oops, > if exp in _ExactRatio.decimal_infinite: # INF, NAN, sNAN should read if exp in ('F', 'n', 'N'): # INF, NAN, sNAN of course. What I pasted comes from a micro-optimization I tried, but which doesn't give any benefit. --

[issue20499] Rounding errors with statistics.variance

2014-02-08 Thread Wolfgang Maier
Wolfgang Maier added the comment: I worked out a slightly speedier version of decimal_to_ratio today (Stefan: that's when I duplicated your bug report): from decimal import Context def _decimal_to_ratio (x): _, digits, exp = x.as_tuple() if exp in _ExactRatio.decimal_infinite: # INF,

[issue20499] Rounding errors with statistics.variance

2014-02-07 Thread Stefan Krah
Stefan Krah added the comment: Oscar Benjamin wrote: > If you're going to use decimals though then you can trap inexact and > keep increasing the precision until it becomes exact. For sums that is not necessary. Create a context with MAX_EMAX, MIN_EMIN and MAX_PREC and mpd_add() -- the underlyi

[issue20499] Rounding errors with statistics.variance

2014-02-07 Thread Wolfgang Maier
Wolfgang Maier added the comment: In principle, your approach using itertools.groupby, the existing _sum, your decimalsum, and my _ExactRatio class could be combined. You could call decimalsum for Decimal and subclasses, the current _sum for everything else. _sum would return an _ExactRatio in

[issue20499] Rounding errors with statistics.variance

2014-02-07 Thread Oscar Benjamin
Oscar Benjamin added the comment: A fast Decimal.as_integer_ratio() would be useful in any case. If you're going to use decimals though then you can trap inexact and keep increasing the precision until it becomes exact. The problem is with rationals that cannot be expressed in a finite number of

[issue20499] Rounding errors with statistics.variance

2014-02-07 Thread Wolfgang Maier
Wolfgang Maier added the comment: Ok, I finally managed to get the test suite right for this, so here is the patch diff for everything. I made a few final changes to the module itself (mostly to please the test suite), so I'll edited the complete code as well. -- keywords: +patch Added

[issue20499] Rounding errors with statistics.variance

2014-02-07 Thread Wolfgang Maier
Changes by Wolfgang Maier : Added file: http://bugs.python.org/file33959/statistics.py ___ Python tracker ___ ___ Python-bugs-list mailing lis

[issue20499] Rounding errors with statistics.variance

2014-02-07 Thread Wolfgang Maier
Wolfgang Maier added the comment: > We can add a fast Decimal.as_integer_ratio() in C. That would be a terrific thing to have !! Currently, Decimals perform really poorly with the statistics functions and this is entirely due to this bottleneck. With regard to calculating the sum of Decimals

[issue20499] Rounding errors with statistics.variance

2014-02-07 Thread Stefan Krah
Stefan Krah added the comment: We can add a fast Decimal.as_integer_ratio() in C. That said, why is the sum of Decimals not done in decimal arithmetic with a very high context precision? It would be exact and with usual exponents in the range [-384, 383] it should be very fast. >>> c.prec = 50

[issue20499] Rounding errors with statistics.variance

2014-02-07 Thread Wolfgang Maier
Wolfgang Maier added the comment: I have written a patch for this issue (I'm uploading the complete new code for everyone to try it - importing it into Python3.3 works fine; a diff with additional tests against Oscar's example will follow soon). Just as Oscar suggested, this new version perform

[issue20499] Rounding errors with statistics.variance

2014-02-06 Thread Oscar Benjamin
Changes by Oscar Benjamin : -- nosy: +wolma ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python

[issue20499] Rounding errors with statistics.variance

2014-02-03 Thread Oscar Benjamin
New submission from Oscar Benjamin: The mean/variance functions in the statistics module don't quite round correctly. The reasons for this are that although exact rational arithmetic is used internally in the _sum function it is not used throughout the module. In particular the _sum function