Skip to content

Commit 374c5ac

Browse files
committed
Add __exit__ methods to PandasSQL
1 parent 2bd274d commit 374c5ac

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

Diff for: pandas/io/sql.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -1455,7 +1455,8 @@ class PandasSQL(PandasObject, ABC):
14551455
def __enter__(self) -> Self:
14561456
return self
14571457

1458-
def __exit__(self, *args) -> None:
1458+
@abstractmethod
1459+
def __exit__(self, exc_type, exc_value, traceback) -> None:
14591460
pass
14601461

14611462
def read_table(
@@ -1647,7 +1648,7 @@ def __init__(
16471648
self.meta = MetaData(schema=schema)
16481649
self.returns_generator = False
16491650

1650-
def __exit__(self, *args) -> None:
1651+
def __exit__(self, exc_type, exc_value, traceback) -> None:
16511652
if not self.returns_generator:
16521653
self.exit_stack.close()
16531654

@@ -2126,6 +2127,9 @@ class ADBCDatabase(PandasSQL):
21262127
def __init__(self, con) -> None:
21272128
self.con = con
21282129

2130+
def __exit__(self, exc_type, exc_value, traceback) -> None:
2131+
self.con.close()
2132+
21292133
@contextmanager
21302134
def run_transaction(self):
21312135
with self.con.cursor() as cur:
@@ -2679,6 +2683,9 @@ class SQLiteDatabase(PandasSQL):
26792683
def __init__(self, con) -> None:
26802684
self.con = con
26812685

2686+
def __exit__(self, exc_type, exc_value, traceback) -> None:
2687+
self.con.close()
2688+
26822689
@contextmanager
26832690
def run_transaction(self):
26842691
cur = self.con.cursor()

0 commit comments

Comments
 (0)