From d4c835ba89a064246c3ad1da6762fd0878b56b3a Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Mon, 11 Nov 2024 18:17:03 -0600 Subject: [PATCH] scripts: csv.py: Fixed divide by zero in ratio This now returns 1.0 if the total part of the fraction is 0. There may be a better way to handle this, but the intention is for 0/0 to map to 100% for thing like code coverage (cov.py), test coverage (test.py), etc. --- scripts/csv.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/csv.py b/scripts/csv.py index 0c94c966..a6007f70 100755 --- a/scripts/csv.py +++ b/scripts/csv.py @@ -597,7 +597,10 @@ class RExpr: def eval(self, fields={}): v = self.a.eval(fields) - return RFloat(float(v.a) / float(v.b)) + if not float(v.b): + return RFloat(1) + else: + return RFloat(float(v.a) / float(v.b)) @func('total') class Total(Expr):