From ef3c2b15079acaa2bb4ffa3000a79f439d5612f9 Mon Sep 17 00:00:00 2001 From: Andrii Korchak Date: Thu, 18 Mar 2021 13:18:53 -0700 Subject: [PATCH] Fix IndexError when concentration is outside of EPA range --- aqi/algos/base.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/aqi/algos/base.py b/aqi/algos/base.py index bbe087f..80e11b5 100644 --- a/aqi/algos/base.py +++ b/aqi/algos/base.py @@ -76,8 +76,14 @@ def iaqi(self, elem, cc): _cc = Decimal(cc).quantize(self.piecewise['prec'][elem], rounding=ROUND_DOWN) - # define breakpoints for this pollutant at this contentration + # define breakpoints for this pollutant at this concentration bps = self.piecewise['bp'][elem] + bplo_min = bps[0][0] + if _cc < bplo_min: + return Decimal(self.piecewise['aqi'][0][0]) + bphi_max = bps[-1][1] + if _cc > bphi_max: + return Decimal(self.piecewise['aqi'][-1][1]) bplo = None bphi = None idx = 0