From 41911b9aa64648589f11f8511093d8ed64042c84 Mon Sep 17 00:00:00 2001 From: desafinadude Date: Wed, 10 Dec 2025 19:21:35 +0200 Subject: [PATCH] Dealing with Nones --- helpers.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/helpers.py b/helpers.py index f9b0369..1e198fb 100644 --- a/helpers.py +++ b/helpers.py @@ -585,8 +585,18 @@ def tsv_to_json_pandas(tsv_string, project_id): # Other types: leave as is # Replace all NaN with None for JSON compatibility + import math + def clean_nans(obj): + if isinstance(obj, float) and math.isnan(obj): + return None + if isinstance(obj, dict): + return {k: clean_nans(v) for k, v in obj.items()} + if isinstance(obj, list): + return [clean_nans(x) for x in obj] + return obj + df = df.where(pd.notnull(df), None) - json_list = df.to_dict('records') + json_list = [clean_nans(row) for row in df.to_dict('records')] return json_list