Serialize list of Obs in pandas.to_sql (#162)

* feat: Added serialization of list of Obs in pandas.to_sql.

* tests: test for list of Obs to sql added.

* feat: auto_gamma functionality added for deserialization of lists of
Obs.
This commit is contained in:
Fabian Joswig 2023-03-10 14:17:20 +00:00 committed by GitHub
parent a7a098b861
commit 3c942b380d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 1 deletions

View file

@ -72,3 +72,15 @@ def test_sql_if_exists_fail(tmp_path):
pe.input.pandas.to_sql(pe_df, "My_table", my_db)
pe.input.pandas.to_sql(pe_df, "My_table", my_db, if_exists='append')
pe.input.pandas.to_sql(pe_df, "My_table", my_db, if_exists='replace')
def test_Obs_list_sql(tmp_path):
my_dict = {"int": 1,
"Obs1": pe.pseudo_Obs(17, 11, "test_sql_if_exists_failnsemble"),
"Obs_list": [[pe.pseudo_Obs(0.0, 0.1, "test_ensemble2"), pe.pseudo_Obs(3.2, 1.1, "test_ensemble2")]]}
pe_df = pd.DataFrame(my_dict)
my_db = (tmp_path / "test_db.sqlite").as_posix()
pe.input.pandas.to_sql(pe_df, "My_table", my_db)
for auto_gamma in [False, True]:
re_df = pe.input.pandas.read_sql("SELECT * from My_table", my_db, auto_gamma=auto_gamma)
assert np.all(re_df == pe_df)