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(