From e22d9cee3a6fe420ec9962281a7d71c2b1eae0a2 Mon Sep 17 00:00:00 2001 From: Thang Pham Date: Wed, 8 Jun 2022 09:15:12 -0400 Subject: [PATCH] fix `ZeroDivisionError` in `scripts/generate_perf_report_page` (#1906) Fixes the `ZeroDivisionError` error by adding `EPS=1e-6` when doing the calculation. --- scripts/generate_perf_report_page.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/generate_perf_report_page.py b/scripts/generate_perf_report_page.py index a15d04e056..23fa4b76a3 100755 --- a/scripts/generate_perf_report_page.py +++ b/scripts/generate_perf_report_page.py @@ -26,6 +26,7 @@ KEY_EXCLUDE_FIELDS = frozenset({ }) NEGATIVE_COLOR = 'negative' POSITIVE_COLOR = 'positive' +EPS = 1e-6 @dataclass @@ -120,7 +121,8 @@ def get_row_values(columns: List[str], run_result: SuitRun, # this might happen when new metric is added and there is no value for it in previous run # let this be here, TODO add proper handling when this actually happens raise ValueError(f'{column} not found in previous result') - ratio = float(value) / float(prev_value['value']) - 1 + # adding `EPS` to each term to avoid ZeroDivisionError when the denominator is zero + ratio = (float(value) + EPS) / (float(prev_value['value']) + EPS) - 1 ratio_display, color = format_ratio(ratio, current_value['report']) row_values.append(RowValue(value, color, ratio_display)) return row_values