Skip to content

Commit dd209fd

Browse files
shabab477pmhatre1
authored andcommitted
BUG: Fixed ADBC to_sql creation of table when using public schema (pandas-dev#57974)
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 115cbe1 commit dd209fd

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
@@ -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

+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)