removing the Pandas 'sqlalchemy' warning by refactoring.
This commit is contained in:
parent
0578efa799
commit
4ebdce2a89
@ -23,7 +23,7 @@ class SQLHandler():
|
|||||||
self.read_all(self.all_schemas)
|
self.read_all(self.all_schemas)
|
||||||
|
|
||||||
def get_all_schemas_from_mysql(self):
|
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")
|
cursor.execute("SHOW TABLES")
|
||||||
schema = cursor.fetchall()
|
schema = cursor.fetchall()
|
||||||
all_schemas = [schem[0] for schem in schema]
|
all_schemas = [schem[0] for schem in schema]
|
||||||
@ -42,8 +42,7 @@ class SQLHandler():
|
|||||||
|
|
||||||
def read_mysql_table_to_df(self, table_name:str):
|
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"""
|
"""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: #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:
|
|
||||||
# 1.) get the column names
|
# 1.) get the column names
|
||||||
cursor.execute(f"DESCRIBE {table_name}")
|
cursor.execute(f"DESCRIBE {table_name}")
|
||||||
cols = cursor.fetchall()
|
cols = cursor.fetchall()
|
||||||
@ -66,8 +65,7 @@ class SQLHandler():
|
|||||||
|
|
||||||
def mysql_to_df(self, query, table_name):
|
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"""
|
"""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: # 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:
|
|
||||||
# 1.) get the column names
|
# 1.) get the column names
|
||||||
cursor.execute(f"DESCRIBE {table_name}")
|
cursor.execute(f"DESCRIBE {table_name}")
|
||||||
cols = cursor.fetchall()
|
cols = cursor.fetchall()
|
||||||
|
|||||||
Reference in New Issue
Block a user