mirror of
https://github.com/fjosw/pyerrors.git
synced 2025-05-14 19:43:41 +02:00
[Fix] Add closing context.
This commit is contained in:
parent
db7326f86b
commit
3901a632b1
1 changed files with 3 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
||||||
import warnings
|
import warnings
|
||||||
import gzip
|
import gzip
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
from contextlib import closing
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from ..obs import Obs
|
from ..obs import Obs
|
||||||
from ..correlators import Corr
|
from ..correlators import Corr
|
||||||
|
@ -29,7 +30,7 @@ def to_sql(df, table_name, db, if_exists='fail', gz=True, **kwargs):
|
||||||
None
|
None
|
||||||
"""
|
"""
|
||||||
se_df = _serialize_df(df, gz=gz)
|
se_df = _serialize_df(df, gz=gz)
|
||||||
with sqlite3.connect(db) as con:
|
with closing(sqlite3.connect(db)) as con:
|
||||||
se_df.to_sql(table_name, con=con, if_exists=if_exists, index=False, **kwargs)
|
se_df.to_sql(table_name, con=con, if_exists=if_exists, index=False, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
@ -51,7 +52,7 @@ def read_sql(sql, db, auto_gamma=False, **kwargs):
|
||||||
data : pandas.DataFrame
|
data : pandas.DataFrame
|
||||||
Dataframe with the content of the sqlite database.
|
Dataframe with the content of the sqlite database.
|
||||||
"""
|
"""
|
||||||
with sqlite3.connect(db) as con:
|
with closing(sqlite3.connect(db)) as con:
|
||||||
extract_df = pd.read_sql(sql, con=con, **kwargs)
|
extract_df = pd.read_sql(sql, con=con, **kwargs)
|
||||||
return _deserialize_df(extract_df, auto_gamma=auto_gamma)
|
return _deserialize_df(extract_df, auto_gamma=auto_gamma)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue