From d0b9191c27a1a8525b4440a63ccc496f9817b86c Mon Sep 17 00:00:00 2001 From: cirun Date: Wed, 16 Oct 2024 18:56:50 +0200 Subject: [PATCH] LLCAXCHZF-61/Prevent KeyError when dropping non-existent columns --- ckanext/charts/fetchers.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ckanext/charts/fetchers.py b/ckanext/charts/fetchers.py index 3f0bb93..1f8c806 100644 --- a/ckanext/charts/fetchers.py +++ b/ckanext/charts/fetchers.py @@ -71,7 +71,11 @@ def fetch_data(self) -> pd.DataFrame: .select_from(sa.table(self.resource_id)) .limit(self.limit), get_read_engine(), - ).drop(columns=["_id", "_full_text"]) + ) + + existing_columns = {col for col in {'_id', '_full_text'} if col in df.columns} + if existing_columns: + df = df.drop(columns=existing_columns) if "date_time" in df.columns: try: