diff --git a/app/models/variables.py b/app/models/variables.py index 73d590c..fedacdf 100644 --- a/app/models/variables.py +++ b/app/models/variables.py @@ -1,6 +1,7 @@ +from math import isnan from typing import Any, Dict, List, Optional, Union -from pydantic import BaseModel, Field, constr +from pydantic import BaseModel, Field, constr, validator from app.core.config import Settings @@ -52,6 +53,12 @@ class VariableProperties(BaseModel): monotonic: Optional[int] histogram: Optional[List[Any]] + @validator("*") + def change_nan_to_none(cls, v, field): + if field.outer_type_ is float and isnan(v): + return None + return v + class Variables(BaseModel): __root__: Dict[VARIABLE_COLUMN_CONSTRAINT, VariableProperties]