From 7fdf0dfe0b9e80721cfb761485ad6de377183cb7 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 27 Feb 2024 16:57:54 +0100 Subject: [PATCH] fix fillnans --- idhub/admin/forms.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/idhub/admin/forms.py b/idhub/admin/forms.py index 27f83fe..85d57d5 100644 --- a/idhub/admin/forms.py +++ b/idhub/admin/forms.py @@ -222,16 +222,21 @@ class ImportForm(forms.Form): return data df = pd.read_excel(data) + df.fillna('', inplace=True) + # convert dates to iso 8601 for col in df.select_dtypes(include='datetime').columns: df[col] = df[col].dt.strftime("%Y-%m-%d") + # convert numbers to strings if this is indicate in schema + props = self.json_schema.get("properties", {}) for col in df.select_dtypes(include=['number']).columns: - sc_col = self.json_schema.get("properties", {}).get(col, {}) - if sc_col.get("type") == "string": + type_col = props.get(col, {}).get("type") + + if "string" in type_col: df[col] = df[col].astype(str) - data_pd = df.fillna('').to_dict() + data_pd = df.to_dict() if not data_pd or df.last_valid_index() is None: self.exception("The file you try to import is empty!")