From 94fd4a080a4b9dd30e9f16de051bbb228484380a Mon Sep 17 00:00:00 2001 From: cirun Date: Wed, 24 Jul 2024 12:13:56 +0200 Subject: [PATCH] LLCAXCHZF-55/prevent datetime columns from being converted to large numeric values --- ckanext/charts/fetchers.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ckanext/charts/fetchers.py b/ckanext/charts/fetchers.py index b1b61a0..c152e75 100644 --- a/ckanext/charts/fetchers.py +++ b/ckanext/charts/fetchers.py @@ -73,8 +73,10 @@ def fetch_data(self) -> pd.DataFrame: get_read_engine(), ).drop(columns=["_id", "_full_text"]) - # TODO: hack... Convert all columns to numeric if possible - df = cast(pd.DataFrame, df.apply(pd.to_numeric, errors='ignore').fillna(0)) + # Identify columns that are not datetime + non_datetime_cols = df.select_dtypes(exclude=['datetime']).columns + # Apply numeric conversion only to non-datetime columns + df[non_datetime_cols] = df[non_datetime_cols].apply(pd.to_numeric, errors='ignore').fillna(0) except (ProgrammingError, UndefinedTable) as e: raise exception.DataFetchError(