refactor: pandas.read_sql_query renamed to read_sql and can now also

directly extract full tables.
This commit is contained in:
Fabian Joswig 2022-07-05 13:31:41 +01:00
parent 1d492dfa67
commit de51d6ca07
2 changed files with 3 additions and 3 deletions

View file

@ -29,7 +29,7 @@ def to_sql(df, table_name, db, if_exists='fail', gz=True):
con.close() con.close()
def read_sql_query(sql, db, auto_gamma=False): def read_sql(sql, db, auto_gamma=False):
"""Execute SQL query on sqlite database and obtain DataFrame including Obs or Corr valued columns. """Execute SQL query on sqlite database and obtain DataFrame including Obs or Corr valued columns.
Parameters Parameters
@ -43,7 +43,7 @@ def read_sql_query(sql, db, auto_gamma=False):
the error analysis. Default False. the error analysis. Default False.
""" """
con = sqlite3.connect(db) con = sqlite3.connect(db)
extract_df = pd.read_sql_query(sql, con) extract_df = pd.read_sql(sql, con)
con.close() con.close()
return _deserialize_df(extract_df, auto_gamma=auto_gamma) return _deserialize_df(extract_df, auto_gamma=auto_gamma)

View file

@ -60,7 +60,7 @@ def test_sql(tmp_path):
my_db = (tmp_path / "test_db.sqlite").as_posix() my_db = (tmp_path / "test_db.sqlite").as_posix()
pe.input.pandas.to_sql(pe_df, "My_table", my_db) pe.input.pandas.to_sql(pe_df, "My_table", my_db)
for auto_gamma in [False, True]: for auto_gamma in [False, True]:
re_df = pe.input.pandas.read_sql_query("SELECT * from My_table", my_db, auto_gamma=auto_gamma) re_df = pe.input.pandas.read_sql("SELECT * from My_table", my_db, auto_gamma=auto_gamma)
assert np.all(re_df == pe_df) assert np.all(re_df == pe_df)