Skip to content

Commit

Permalink
Add NaN check
Browse files Browse the repository at this point in the history
  • Loading branch information
dgboss committed Jul 23, 2024
1 parent 2f9126e commit d27bca2
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions api/app/weather_models/machine_learning.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Check warning on line 269 in api/app/weather_models/machine_learning.py

View check run for this annotation

Codecov / codecov/patch

api/app/weather_models/machine_learning.py#L268-L269

Added lines #L268 - L269 were not covered by tests
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:
Expand Down

0 comments on commit d27bca2

Please sign in to comment.