Skip to content

Commit f455401

Browse files
Backport PR #57974 on branch 2.2.x (BUG: Fixed ADBC to_sql creation of table when using public schema) (#58050)
Backport PR #57974: BUG: Fixed ADBC to_sql creation of table when using public schema Co-authored-by: Shabab Karim <[email protected]>
1 parent e1a7302 commit f455401

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

doc/source/whatsnew/v2.2.2.rst

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Bug fixes
2525
- :meth:`DataFrame.__dataframe__` was producing incorrect data buffers when the column's type was nullable boolean (:issue:`55332`)
2626
- :meth:`DataFrame.__dataframe__` was showing bytemask instead of bitmask for ``'string[pyarrow]'`` validity buffer (:issue:`57762`)
2727
- :meth:`DataFrame.__dataframe__` was showing non-null validity buffer (instead of ``None``) ``'string[pyarrow]'`` without missing values (:issue:`57761`)
28+
- :meth:`DataFrame.to_sql` was failing to find the right table when using the schema argument (:issue:`57539`)
2829

2930
.. ---------------------------------------------------------------------------
3031
.. _whatsnew_222.other:

pandas/io/sql.py

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

24022402
with self.con.cursor() as cur:
2403-
total_inserted = cur.adbc_ingest(table_name, tbl, mode=mode)
2403+
total_inserted = cur.adbc_ingest(
2404+
table_name=name, data=tbl, mode=mode, db_schema_name=schema
2405+
)
24042406

24052407
self.con.commit()
24062408
return total_inserted

pandas/tests/io/test_sql.py

+24
Original file line numberDiff line numberDiff line change
@@ -1373,6 +1373,30 @@ def insert_on_conflict(table, conn, keys, data_iter):
13731373
pandasSQL.drop_table("test_insert_conflict")
13741374

13751375

1376+
@pytest.mark.parametrize("conn", all_connectable)
1377+
def test_to_sql_on_public_schema(conn, request):
1378+
if "sqlite" in conn or "mysql" in conn:
1379+
request.applymarker(
1380+
pytest.mark.xfail(
1381+
reason="test for public schema only specific to postgresql"
1382+
)
1383+
)
1384+
1385+
conn = request.getfixturevalue(conn)
1386+
1387+
test_data = DataFrame([[1, 2.1, "a"], [2, 3.1, "b"]], columns=list("abc"))
1388+
test_data.to_sql(
1389+
name="test_public_schema",
1390+
con=conn,
1391+
if_exists="append",
1392+
index=False,
1393+
schema="public",
1394+
)
1395+
1396+
df_out = sql.read_sql_table("test_public_schema", conn, schema="public")
1397+
tm.assert_frame_equal(test_data, df_out)
1398+
1399+
13761400
@pytest.mark.parametrize("conn", mysql_connectable)
13771401
def test_insertion_method_on_conflict_update(conn, request):
13781402
# GH 14553: Example in to_sql docstring

0 commit comments

Comments
 (0)