removing the Pandas 'sqlalchemy' warning by refactoring.

This commit is contained in:
scopesorting 2023-11-04 10:08:47 +01:00
parent 0578efa799
commit 4ebdce2a89

View File

@ -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()