From c4c4855d3e797f364db30f38ce06ae64a127e50d Mon Sep 17 00:00:00 2001 From: pcain <pcain@usgs.gov> Date: Tue, 28 Sep 2021 15:47:13 -0600 Subject: [PATCH] response NaNs as null --- geomagio/api/ws/algorithms.py | 9 ++++++--- geomagio/residual/Diagnostics.py | 3 +-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/geomagio/api/ws/algorithms.py b/geomagio/api/ws/algorithms.py index 6bf055c33..eaf58451a 100644 --- a/geomagio/api/ws/algorithms.py +++ b/geomagio/api/ws/algorithms.py @@ -1,8 +1,8 @@ -from os import name +import json + from fastapi import APIRouter, Depends, HTTPException from starlette.responses import Response -from ... import TimeseriesFactory from ...algorithm import DbDtAlgorithm from ...residual import ( calculate, @@ -44,6 +44,9 @@ def get_dbdt( ) def calculate_residual(reading: Reading, adjust_reference: bool = True): try: - return calculate(reading=reading, adjust_reference=adjust_reference) + calculated = calculate( + reading=reading, adjust_reference=adjust_reference + ).json() + return json.loads(calculated.replace("NaN", "null")) except ValueError as e: raise HTTPException(status_code=400, detail=str(e)) diff --git a/geomagio/residual/Diagnostics.py b/geomagio/residual/Diagnostics.py index fd9dac1c9..42f8572a7 100644 --- a/geomagio/residual/Diagnostics.py +++ b/geomagio/residual/Diagnostics.py @@ -1,6 +1,5 @@ from typing import Optional -from .Measurement import Measurement from pydantic import BaseModel @@ -14,4 +13,4 @@ class Diagnostics(BaseModel): """ inclination: float - meridian: float + meridian: Optional[float] = None -- GitLab