Skip to content

Commit

Permalink
Use pandasSQL transactions in sql test suite to avoid engine deadlocks (
Browse files Browse the repository at this point in the history
pandas-dev#55129)

pandasSQL use transactions in test suite
  • Loading branch information
WillAyd authored and hedeershowk committed Sep 20, 2023
1 parent 9d4a773 commit bbf20f9
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions pandas/tests/io/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -1141,18 +1141,21 @@ def load_types_data(self, types_data):
def _read_sql_iris_parameter(self, sql_strings):
query = sql_strings["read_parameters"][self.flavor]
params = ("Iris-setosa", 5.1)
iris_frame = self.pandasSQL.read_query(query, params=params)
with self.pandasSQL.run_transaction():
iris_frame = self.pandasSQL.read_query(query, params=params)
check_iris_frame(iris_frame)

def _read_sql_iris_named_parameter(self, sql_strings):
query = sql_strings["read_named_parameters"][self.flavor]
params = {"name": "Iris-setosa", "length": 5.1}
iris_frame = self.pandasSQL.read_query(query, params=params)
with self.pandasSQL.run_transaction():
iris_frame = self.pandasSQL.read_query(query, params=params)
check_iris_frame(iris_frame)

def _read_sql_iris_no_parameter_with_percent(self, sql_strings):
query = sql_strings["read_no_parameters_with_percent"][self.flavor]
iris_frame = self.pandasSQL.read_query(query, params=None)
with self.pandasSQL.run_transaction():
iris_frame = self.pandasSQL.read_query(query, params=None)
check_iris_frame(iris_frame)

def _to_sql_empty(self, test_frame1):
Expand Down Expand Up @@ -1182,7 +1185,8 @@ def _to_sql_with_sql_engine(self, test_frame1, engine="auto", **engine_kwargs):
def _roundtrip(self, test_frame1):
self.drop_table("test_frame_roundtrip", self.conn)
assert self.pandasSQL.to_sql(test_frame1, "test_frame_roundtrip") == 4
result = self.pandasSQL.read_query("SELECT * FROM test_frame_roundtrip")
with self.pandasSQL.run_transaction():
result = self.pandasSQL.read_query("SELECT * FROM test_frame_roundtrip")

result.set_index("level_0", inplace=True)
# result.index.astype(int)
Expand Down Expand Up @@ -1232,13 +1236,14 @@ class DummyException(Exception):
except DummyException:
# ignore raised exception
pass
res = self.pandasSQL.read_query("SELECT * FROM test_trans")
with self.pandasSQL.run_transaction():
res = self.pandasSQL.read_query("SELECT * FROM test_trans")
assert len(res) == 0

# Make sure when transaction is committed, rows do get inserted
with self.pandasSQL.run_transaction() as trans:
trans.execute(ins_sql)
res2 = self.pandasSQL.read_query("SELECT * FROM test_trans")
res2 = self.pandasSQL.read_query("SELECT * FROM test_trans")
assert len(res2) == 1


Expand Down

0 comments on commit bbf20f9

Please sign in to comment.