Fix api_schemas/json_encoders by manually converting NaT values to empty Strings

makes import of datetime columns more robust by first checking
if value is null because strftime can't handle NaT values

use `isnull()` because it handles all NaN/None/NaT cases
This commit is contained in:
Joe Schr 2022-02-01 19:34:50 +01:00
parent 06387478b5
commit 118ae8a3d0

View File

@ -1,4 +1,5 @@
from datetime import date, datetime
from pandas import isnull
from typing import Any, Dict, List, Optional, Union
from pydantic import BaseModel
@ -355,7 +356,9 @@ class PairHistory(BaseModel):
class Config:
json_encoders = {
datetime: lambda v: v.strftime(DATETIME_PRINT_FORMAT),
datetime: lambda v: v.strftime(DATETIME_PRINT_FORMAT)
# needed for aslong NaT doesn't work with strftime
if not isnull(v) else "",
}