From 5d3bb954a8e66a4bf2df4fbd02a7b1094c77492b Mon Sep 17 00:00:00 2001 From: Filipe Fernandes Date: Wed, 3 Apr 2024 16:25:32 +0200 Subject: [PATCH] fail gracefully when a metric returns None --- ioos_metrics/ioos_metrics.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ioos_metrics/ioos_metrics.py b/ioos_metrics/ioos_metrics.py index 69e93bd..71c53d7 100644 --- a/ioos_metrics/ioos_metrics.py +++ b/ioos_metrics/ioos_metrics.py @@ -57,6 +57,8 @@ def _compare_metrics(column, num): Compares last stored metric against the new one and report if it is up, down, or the same. """ + if num is None: + return f"[{date}] : {column} failed." last_row = previous_metrics().iloc[-1] date = last_row["date_UTC"] old = last_row[column] @@ -212,7 +214,8 @@ def atn_deployments(): headers = {"Accept": "application/json"} raw_payload = requests.get( - "https://search.axds.co/v2/search?portalId=99", headers=headers + "https://search.axds.co/v2/search?portalId=99", + headers=headers, ) json_payload = raw_payload.json() for plt in json_payload["types"]: @@ -296,7 +299,9 @@ def ioos_core_variables(): # Drop the rows where 'name' doesn't exist. df = df.dropna( - axis="index", how="any", subset="http://mmisw.org/ont/ioos/core_variable/name" + axis="index", + how="any", + subset="http://mmisw.org/ont/ioos/core_variable/name", ) return len(df.index.tolist())