@@ -1317,23 +1317,25 @@ def psql_insert_copy(table, conn, keys, data_iter):
1317
1317
return expected_count
1318
1318
1319
1319
conn = request .getfixturevalue (conn )
1320
+ table_uuid = table_uuid_gen ("test_frame" )
1320
1321
expected = DataFrame ({"col1" : [1 , 2 ], "col2" : [0.1 , 0.2 ], "col3" : ["a" , "n" ]})
1321
1322
result_count = expected .to_sql (
1322
- name = "test_frame" , con = conn , index = False , method = psql_insert_copy
1323
+ name = table_uuid , con = conn , index = False , method = psql_insert_copy
1323
1324
)
1324
1325
# GH 46891
1325
1326
if expected_count is None :
1326
1327
assert result_count is None
1327
1328
else :
1328
1329
assert result_count == expected_count
1329
- result = sql .read_sql_table ("test_frame" , conn )
1330
+ result = sql .read_sql_table (table_uuid , conn )
1330
1331
tm .assert_frame_equal (result , expected )
1331
1332
1332
1333
1333
1334
@pytest .mark .parametrize ("conn" , postgresql_connectable )
1334
1335
def test_insertion_method_on_conflict_do_nothing (conn , request ):
1335
1336
# GH 15988: Example in to_sql docstring
1336
1337
conn = request .getfixturevalue (conn )
1338
+ table_uuid = table_uuid_gen ("test_insert_conflict" )
1337
1339
1338
1340
from sqlalchemy .dialects .postgresql import insert
1339
1341
from sqlalchemy .engine import Engine
@@ -1350,8 +1352,8 @@ def insert_on_conflict(table, conn, keys, data_iter):
1350
1352
return result .rowcount
1351
1353
1352
1354
create_sql = text (
1353
- """
1354
- CREATE TABLE test_insert_conflict (
1355
+ f """
1356
+ CREATE TABLE { table_uuid } (
1355
1357
a integer PRIMARY KEY,
1356
1358
b numeric,
1357
1359
c text
@@ -1368,24 +1370,24 @@ def insert_on_conflict(table, conn, keys, data_iter):
1368
1370
1369
1371
expected = DataFrame ([[1 , 2.1 , "a" ]], columns = list ("abc" ))
1370
1372
expected .to_sql (
1371
- name = "test_insert_conflict" , con = conn , if_exists = "append" , index = False
1373
+ name = table_uuid , con = conn , if_exists = "append" , index = False
1372
1374
)
1373
1375
1374
1376
df_insert = DataFrame ([[1 , 3.2 , "b" ]], columns = list ("abc" ))
1375
1377
inserted = df_insert .to_sql (
1376
- name = "test_insert_conflict" ,
1378
+ name = table_uuid ,
1377
1379
con = conn ,
1378
1380
index = False ,
1379
1381
if_exists = "append" ,
1380
1382
method = insert_on_conflict ,
1381
1383
)
1382
- result = sql .read_sql_table ("test_insert_conflict" , conn )
1384
+ result = sql .read_sql_table (table_uuid , conn )
1383
1385
tm .assert_frame_equal (result , expected )
1384
1386
assert inserted == 0
1385
1387
1386
1388
# Cleanup
1387
1389
with sql .SQLDatabase (conn , need_transaction = True ) as pandasSQL :
1388
- pandasSQL .drop_table ("test_insert_conflict" )
1390
+ pandasSQL .drop_table (table_uuid )
1389
1391
1390
1392
1391
1393
@pytest .mark .parametrize ("conn" , all_connectable )
@@ -1474,8 +1476,8 @@ def test_read_view_postgres(conn, request):
1474
1476
from sqlalchemy .engine import Engine
1475
1477
from sqlalchemy .sql import text
1476
1478
1477
- table_name = f"group_ { uuid . uuid4 (). hex } "
1478
- view_name = f"group_view_ { uuid . uuid4 (). hex } "
1479
+ table_name = table_uuid_gen ( "group" )
1480
+ view_name = table_uuid_gen ( "group_view" )
1479
1481
1480
1482
sql_stmt = text (
1481
1483
f"""
@@ -2864,21 +2866,23 @@ def test_datetime_with_timezone_query(conn, request, parse_dates):
2864
2866
# to datetime64[ns,psycopg2.tz.FixedOffsetTimezone..], which is ok
2865
2867
# but should be more natural, so coerce to datetime64[ns] for now
2866
2868
conn = request .getfixturevalue (conn )
2869
+ table_uuid = table_uuid_gen ("datetz" )
2867
2870
expected = create_and_load_postgres_datetz (conn )
2868
2871
2869
2872
# GH11216
2870
- df = read_sql_query ("select * from datetz " , conn , parse_dates = parse_dates )
2873
+ df = read_sql_query (f "select * from { table_uuid } " , conn , parse_dates = parse_dates )
2871
2874
col = df .DateColWithTz
2872
2875
tm .assert_series_equal (col , expected )
2873
2876
2874
2877
2875
2878
@pytest .mark .parametrize ("conn" , postgresql_connectable )
2876
2879
def test_datetime_with_timezone_query_chunksize (conn , request ):
2877
2880
conn = request .getfixturevalue (conn )
2881
+ table_uuid = table_uuid_gen ("datetz" )
2878
2882
expected = create_and_load_postgres_datetz (conn )
2879
2883
2880
2884
df = concat (
2881
- list (read_sql_query ("select * from datetz " , conn , chunksize = 1 )),
2885
+ list (read_sql_query (f "select * from { table_uuid } " , conn , chunksize = 1 )),
2882
2886
ignore_index = True ,
2883
2887
)
2884
2888
col = df .DateColWithTz
@@ -2888,8 +2892,9 @@ def test_datetime_with_timezone_query_chunksize(conn, request):
2888
2892
@pytest .mark .parametrize ("conn" , postgresql_connectable )
2889
2893
def test_datetime_with_timezone_table (conn , request ):
2890
2894
conn = request .getfixturevalue (conn )
2895
+ table_uuid = table_uuid_gen ("datetz" )
2891
2896
expected = create_and_load_postgres_datetz (conn )
2892
- result = sql .read_sql_table ("datetz" , conn )
2897
+ result = sql .read_sql_table (table_uuid , conn )
2893
2898
2894
2899
exp_frame = expected .to_frame ()
2895
2900
tm .assert_frame_equal (result , exp_frame )
0 commit comments