From 2aff00662dda83b9f745ef9fb24a8d40d759d4ca Mon Sep 17 00:00:00 2001 From: Gabriel Studer <gabriel.studer@unibas.ch> Date: Fri, 15 Nov 2019 10:06:17 +0100 Subject: [PATCH] Fix issue with changed rounding behaviour in Python 3. Python 3 rounds towards the nearest even number if its in the middle of two integers as opposed to Python 2 that simply rounds to the higher integer number. By doing that we avoid biases towards higher numbers. --- modules/base/pymod/table.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/base/pymod/table.py b/modules/base/pymod/table.py index dc59194e0..bb7714f03 100644 --- a/modules/base/pymod/table.py +++ b/modules/base/pymod/table.py @@ -2002,7 +2002,7 @@ Statistics for column %(col)s .. code-block:: python - values[min(len(values), int(round(len(values)*nth/100+0.5)-1))] + values[min(len(values)-1, int(math.floor(len(values)*nth/100.0)))] where values are the sorted values of *col* not equal to ''None'' @@ -2033,7 +2033,9 @@ Statistics for column %(col)s percentiles=[] for nth in nths: - p=vals[min(len(vals)-1, int(round(len(vals)*nth/100.0+0.5)-1))] + # rounding behaviour between Python2 and Python3 changed.... + # p=vals[min(len(vals)-1, int(round(len(vals)*nth/100.0+0.5)-1))] + p=vals[min(len(vals)-1, int(math.floor(len(vals)*nth/100.0)))] percentiles.append(p) return percentiles -- GitLab