From 1043852f009b78510492aaa1f96f9e8ce968f8ab Mon Sep 17 00:00:00 2001 From: Gabriele Venturi Date: Thu, 18 Jul 2024 21:02:33 +0200 Subject: [PATCH] test: fix tests --- pandasai/connectors/pandas.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pandasai/connectors/pandas.py b/pandasai/connectors/pandas.py index 109931b67..18f1e04ed 100644 --- a/pandasai/connectors/pandas.py +++ b/pandasai/connectors/pandas.py @@ -167,6 +167,13 @@ def enable_sql_query(self, table_name=None): table = table_name or self.name + # Check if the table already exists in DuckDB + existing_tables = duckdb.query("SHOW TABLES").fetchall() + + # If the table already exists, drop it + if table in [t[0] for t in existing_tables]: + duckdb.query(f"DROP TABLE {table}") + duckdb_relation = duckdb.from_df(self.pandas_df) duckdb_relation.create(table) self.sql_enabled = True