From 3901a632b1c05b8ac1a4b5e14e337fa02732d7fa Mon Sep 17 00:00:00 2001 From: Fabian Joswig Date: Mon, 5 May 2025 17:05:56 +0200 Subject: [PATCH] [Fix] Add closing context. --- pyerrors/input/pandas.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pyerrors/input/pandas.py b/pyerrors/input/pandas.py index 7519e9c5..af446cfc 100644 --- a/pyerrors/input/pandas.py +++ b/pyerrors/input/pandas.py @@ -1,6 +1,7 @@ import warnings import gzip import sqlite3 +from contextlib import closing import pandas as pd from ..obs import Obs from ..correlators import Corr @@ -29,7 +30,7 @@ def to_sql(df, table_name, db, if_exists='fail', gz=True, **kwargs): None """ 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) @@ -51,7 +52,7 @@ def read_sql(sql, db, auto_gamma=False, **kwargs): data : pandas.DataFrame 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) return _deserialize_df(extract_df, auto_gamma=auto_gamma)