Skip to content

Commit 1e206b0

Browse files
committed
57539: Fixed creation unnamed table when using public schema
Problem: - Table on public schema being lost when tried to be created Solution: - Used db_schema_name argument to specify schema name of adbc_ingest
1 parent e51039a commit 1e206b0

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

pandas/io/sql.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -2380,7 +2380,9 @@ def to_sql(
23802380
raise ValueError("datatypes not supported") from exc
23812381

23822382
with self.con.cursor() as cur:
2383-
total_inserted = cur.adbc_ingest(table_name, tbl, mode=mode)
2383+
total_inserted = cur.adbc_ingest(
2384+
table_name=name, data=tbl, mode=mode, db_schema_name=schema
2385+
)
23842386

23852387
self.con.commit()
23862388
return total_inserted

pandas/tests/io/test_sql.py

+41-1
Original file line numberDiff line numberDiff line change
@@ -1275,7 +1275,6 @@ def test_read_procedure(conn, request):
12751275
res2 = sql.read_sql("CALL get_testdb();", conn)
12761276
tm.assert_frame_equal(df, res2)
12771277

1278-
12791278
@pytest.mark.parametrize("conn", postgresql_connectable)
12801279
@pytest.mark.parametrize("expected_count", [2, "Success!"])
12811280
def test_copy_from_callable_insertion_method(conn, expected_count, request):
@@ -1373,6 +1372,47 @@ def insert_on_conflict(table, conn, keys, data_iter):
13731372
pandasSQL.drop_table("test_insert_conflict")
13741373

13751374

1375+
@pytest.mark.parametrize("conn", postgresql_connectable)
1376+
def test_to_sql_on_public_schema_postgres(conn, request):
1377+
# GH 15988: Example in to_sql docstring
1378+
conn = request.getfixturevalue(conn)
1379+
1380+
from sqlalchemy.engine import Engine
1381+
from sqlalchemy.sql import text
1382+
1383+
create_sql = text(
1384+
"""
1385+
CREATE TABLE test_public_schema (
1386+
a integer PRIMARY KEY,
1387+
b numeric,
1388+
c text
1389+
);
1390+
"""
1391+
)
1392+
if isinstance(conn, Engine):
1393+
with conn.connect() as con:
1394+
with con.begin():
1395+
con.execute(create_sql)
1396+
else:
1397+
with conn.begin():
1398+
conn.execute(create_sql)
1399+
1400+
test_data = DataFrame([[1, 2.1, "a"], [2, 3.1, "b"]], columns=list("abc"))
1401+
test_data.to_sql(
1402+
name="test_public_schema",
1403+
con=conn,
1404+
if_exists="append",
1405+
index=False,
1406+
schema="public"
1407+
)
1408+
1409+
df_out = sql.read_sql_table("test_public_schema", conn, schema="public")
1410+
assert test_data.equals(df_out)
1411+
1412+
# Cleanup
1413+
with sql.SQLDatabase(conn, need_transaction=True) as pandasSQL:
1414+
pandasSQL.drop_table("test_public_schema")
1415+
13761416
@pytest.mark.parametrize("conn", mysql_connectable)
13771417
def test_insertion_method_on_conflict_update(conn, request):
13781418
# GH 14553: Example in to_sql docstring

0 commit comments

Comments
 (0)