Skip to content

Commit

Permalink
Fix NaN in json error
Browse files Browse the repository at this point in the history
  • Loading branch information
Tharun Paul authored and Tharun Paul committed Apr 3, 2024
1 parent 870168f commit 2e78428
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/models/variables.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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]

0 comments on commit 2e78428

Please sign in to comment.