From 5946d930bf9d29147ac42acadedb55cdd4c0c657 Mon Sep 17 00:00:00 2001 From: cirun Date: Fri, 26 Jul 2024 11:55:59 +0200 Subject: [PATCH] Convert the 'date_time' column to string format in ISO 8601 --- ckanext/charts/fetchers.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ckanext/charts/fetchers.py b/ckanext/charts/fetchers.py index c152e75..d701b1f 100644 --- a/ckanext/charts/fetchers.py +++ b/ckanext/charts/fetchers.py @@ -78,6 +78,10 @@ def fetch_data(self) -> pd.DataFrame: # Apply numeric conversion only to non-datetime columns df[non_datetime_cols] = df[non_datetime_cols].apply(pd.to_numeric, errors='ignore').fillna(0) + if "date_time" in df.columns: + # Convert the 'date_time' column to string format in ISO 8601 + df['date_time'] = df['date_time'].dt.strftime("%Y-%m-%dT%H:%M:%S") + except (ProgrammingError, UndefinedTable) as e: raise exception.DataFetchError( f"An error occurred during fetching data from DataStore: {e}",