Skip to content

Commit bbf20f9

Browse files
WillAydhedeershowk
authored andcommitted
Use pandasSQL transactions in sql test suite to avoid engine deadlocks (pandas-dev#55129)
pandasSQL use transactions in test suite
1 parent 9d4a773 commit bbf20f9

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

pandas/tests/io/test_sql.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -1141,18 +1141,21 @@ def load_types_data(self, types_data):
11411141
def _read_sql_iris_parameter(self, sql_strings):
11421142
query = sql_strings["read_parameters"][self.flavor]
11431143
params = ("Iris-setosa", 5.1)
1144-
iris_frame = self.pandasSQL.read_query(query, params=params)
1144+
with self.pandasSQL.run_transaction():
1145+
iris_frame = self.pandasSQL.read_query(query, params=params)
11451146
check_iris_frame(iris_frame)
11461147

11471148
def _read_sql_iris_named_parameter(self, sql_strings):
11481149
query = sql_strings["read_named_parameters"][self.flavor]
11491150
params = {"name": "Iris-setosa", "length": 5.1}
1150-
iris_frame = self.pandasSQL.read_query(query, params=params)
1151+
with self.pandasSQL.run_transaction():
1152+
iris_frame = self.pandasSQL.read_query(query, params=params)
11511153
check_iris_frame(iris_frame)
11521154

11531155
def _read_sql_iris_no_parameter_with_percent(self, sql_strings):
11541156
query = sql_strings["read_no_parameters_with_percent"][self.flavor]
1155-
iris_frame = self.pandasSQL.read_query(query, params=None)
1157+
with self.pandasSQL.run_transaction():
1158+
iris_frame = self.pandasSQL.read_query(query, params=None)
11561159
check_iris_frame(iris_frame)
11571160

11581161
def _to_sql_empty(self, test_frame1):
@@ -1182,7 +1185,8 @@ def _to_sql_with_sql_engine(self, test_frame1, engine="auto", **engine_kwargs):
11821185
def _roundtrip(self, test_frame1):
11831186
self.drop_table("test_frame_roundtrip", self.conn)
11841187
assert self.pandasSQL.to_sql(test_frame1, "test_frame_roundtrip") == 4
1185-
result = self.pandasSQL.read_query("SELECT * FROM test_frame_roundtrip")
1188+
with self.pandasSQL.run_transaction():
1189+
result = self.pandasSQL.read_query("SELECT * FROM test_frame_roundtrip")
11861190

11871191
result.set_index("level_0", inplace=True)
11881192
# result.index.astype(int)
@@ -1232,13 +1236,14 @@ class DummyException(Exception):
12321236
except DummyException:
12331237
# ignore raised exception
12341238
pass
1235-
res = self.pandasSQL.read_query("SELECT * FROM test_trans")
1239+
with self.pandasSQL.run_transaction():
1240+
res = self.pandasSQL.read_query("SELECT * FROM test_trans")
12361241
assert len(res) == 0
12371242

12381243
# Make sure when transaction is committed, rows do get inserted
12391244
with self.pandasSQL.run_transaction() as trans:
12401245
trans.execute(ins_sql)
1241-
res2 = self.pandasSQL.read_query("SELECT * FROM test_trans")
1246+
res2 = self.pandasSQL.read_query("SELECT * FROM test_trans")
12421247
assert len(res2) == 1
12431248

12441249

0 commit comments

Comments
 (0)