diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index a4c27116..af98e210 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -43,4 +43,4 @@ jobs: uv pip freeze --system - name: Run tests - run: pytest --cov=pyerrors -vv + run: pytest --cov=pyerrors -vv -Werror diff --git a/pyerrors/input/pandas.py b/pyerrors/input/pandas.py index 13482983..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,9 +30,8 @@ def to_sql(df, table_name, db, if_exists='fail', gz=True, **kwargs): None """ se_df = _serialize_df(df, gz=gz) - con = sqlite3.connect(db) - se_df.to_sql(table_name, con, if_exists=if_exists, index=False, **kwargs) - con.close() + with closing(sqlite3.connect(db)) as con: + se_df.to_sql(table_name, con=con, if_exists=if_exists, index=False, **kwargs) def read_sql(sql, db, auto_gamma=False, **kwargs): @@ -52,9 +52,8 @@ def read_sql(sql, db, auto_gamma=False, **kwargs): data : pandas.DataFrame Dataframe with the content of the sqlite database. """ - con = sqlite3.connect(db) - extract_df = pd.read_sql(sql, con, **kwargs) - con.close() + 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)