From 6de426c6974c829f33b84b19f3c9f305283b5343 Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Wed, 24 Jul 2024 09:58:42 -0500 Subject: [PATCH] Prevent pandas overflow and runtime errors from division by zero/NaN (#12591) * Prevent pandas overflow and runtime errors from division by zero/NaN * remove pysqlite3 --- frigate/api/review.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/frigate/api/review.py b/frigate/api/review.py index 7f17c77e1..6bb2a4800 100644 --- a/frigate/api/review.py +++ b/frigate/api/review.py @@ -475,7 +475,7 @@ def motion_activity(): logger.warning("No motion data found for the requested time range") return jsonify([]) - df = df.astype(dtype={"motion": "float16"}) + df = df.astype(dtype={"motion": "float32"}) # set date as datetime index df["start_time"] = pd.to_datetime(df["start_time"], unit="s") @@ -497,11 +497,13 @@ def motion_activity(): for i in range(0, length, chunk): part = df.iloc[i : i + chunk] - df.iloc[i : i + chunk, 0] = ( - (part["motion"] - part["motion"].min()) - / (part["motion"].max() - part["motion"].min()) - * 100 - ).fillna(0.0) + min_val, max_val = part["motion"].min(), part["motion"].max() + if min_val != max_val: + df.iloc[i : i + chunk, 0] = ( + part["motion"].sub(min_val).div(max_val - min_val).mul(100).fillna(0) + ) + else: + df.iloc[i : i + chunk, 0] = 0.0 # change types for output df.index = df.index.astype(int) // (10**9)