From 4ebdce2a8951a57acbd5745cee2068f567ecc7df Mon Sep 17 00:00:00 2001 From: scopesorting Date: Sat, 4 Nov 2023 10:08:47 +0100 Subject: [PATCH] removing the Pandas 'sqlalchemy' warning by refactoring. --- src/server/BreCal/database/sql_handler.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/server/BreCal/database/sql_handler.py b/src/server/BreCal/database/sql_handler.py index 51e9d31..14bf472 100644 --- a/src/server/BreCal/database/sql_handler.py +++ b/src/server/BreCal/database/sql_handler.py @@ -23,7 +23,7 @@ class SQLHandler(): self.read_all(self.all_schemas) def get_all_schemas_from_mysql(self): - with self.sql_connection.cursor(buffered=True) as cursor: # with self.engine.connect() as sql_engine: + with self.sql_connection.cursor(buffered=True) as cursor: cursor.execute("SHOW TABLES") schema = cursor.fetchall() all_schemas = [schem[0] for schem in schema] @@ -42,8 +42,7 @@ class SQLHandler(): def read_mysql_table_to_df(self, table_name:str): """determine a {table_name}, which will be read from a mysql server. returns a pandas DataFrame with the respective data""" - #df = pd.read_sql(sql=f"SELECT * FROM {table_name}", con=self.sql_connection) - with self.sql_connection.cursor(buffered=True) as cursor: # with self.engine.connect() as sql_engine: + with self.sql_connection.cursor(buffered=True) as cursor: #df = pd.read_sql(sql=f"SELECT * FROM {table_name}", con=self.sql_connection) # 1.) get the column names cursor.execute(f"DESCRIBE {table_name}") cols = cursor.fetchall() @@ -66,8 +65,7 @@ class SQLHandler(): def mysql_to_df(self, query, table_name): """provide an arbitrary sql query that should be read from a mysql server {sql_connection}. returns a pandas DataFrame with the obtained data""" - # df = pd.read_sql(query, self.sql_connection).convert_dtypes() - with self.sql_connection.cursor(buffered=True) as cursor: # with self.engine.connect() as sql_engine: + with self.sql_connection.cursor(buffered=True) as cursor: # df = pd.read_sql(query, self.sql_connection).convert_dtypes() # 1.) get the column names cursor.execute(f"DESCRIBE {table_name}") cols = cursor.fetchall()