From d27bca205aac80a889a6119f575c8f23faa833c5 Mon Sep 17 00:00:00 2001 From: Darren Boss Date: Tue, 23 Jul 2024 12:09:16 -0700 Subject: [PATCH] Add NaN check --- api/app/weather_models/machine_learning.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/api/app/weather_models/machine_learning.py b/api/app/weather_models/machine_learning.py index 04794d079..57762de47 100644 --- a/api/app/weather_models/machine_learning.py +++ b/api/app/weather_models/machine_learning.py @@ -6,6 +6,7 @@ from typing import List from logging import getLogger from sklearn.linear_model import LinearRegression +import math import numpy as np from sqlalchemy.orm import Session from app.weather_models import SCALAR_MODEL_VALUE_KEYS @@ -263,6 +264,9 @@ def predict_precipitation(self, model_precipitation: float, timestamp: datetime) if model_precipitation is None: logger.warning('model precipitation for %s was None', timestamp) return None + if math.isnan(model_precipitation): + logger.warning("model precipitation for %s was NaN", timestamp) + return None hour = timestamp.hour predicted_precip_24h = self.regression_models_v2._precip_model.predict(hour, [[model_precipitation]]) if predicted_precip_24h is None or len(predicted_precip_24h) == 0: