Skip to content

Commit

Permalink
Backport PR pandas-dev#57974: BUG: Fixed ADBC to_sql creation of tabl…
Browse files Browse the repository at this point in the history
…e when using public schema
  • Loading branch information
shabab477 authored and meeseeksmachine committed Mar 28, 2024
1 parent e1a7302 commit 5eecbd0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.2.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Bug fixes
- :meth:`DataFrame.__dataframe__` was producing incorrect data buffers when the column's type was nullable boolean (:issue:`55332`)
- :meth:`DataFrame.__dataframe__` was showing bytemask instead of bitmask for ``'string[pyarrow]'`` validity buffer (:issue:`57762`)
- :meth:`DataFrame.__dataframe__` was showing non-null validity buffer (instead of ``None``) ``'string[pyarrow]'`` without missing values (:issue:`57761`)
- :meth:`DataFrame.to_sql` was failing to find the right table when using the schema argument (:issue:`57539`)

.. ---------------------------------------------------------------------------
.. _whatsnew_222.other:
Expand Down
4 changes: 3 additions & 1 deletion pandas/io/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -2400,7 +2400,9 @@ def to_sql(
raise ValueError("datatypes not supported") from exc

with self.con.cursor() as cur:
total_inserted = cur.adbc_ingest(table_name, tbl, mode=mode)
total_inserted = cur.adbc_ingest(
table_name=name, data=tbl, mode=mode, db_schema_name=schema
)

self.con.commit()
return total_inserted
Expand Down
24 changes: 24 additions & 0 deletions pandas/tests/io/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -1373,6 +1373,30 @@ def insert_on_conflict(table, conn, keys, data_iter):
pandasSQL.drop_table("test_insert_conflict")


@pytest.mark.parametrize("conn", all_connectable)
def test_to_sql_on_public_schema(conn, request):
if "sqlite" in conn or "mysql" in conn:
request.applymarker(
pytest.mark.xfail(
reason="test for public schema only specific to postgresql"
)
)

conn = request.getfixturevalue(conn)

test_data = DataFrame([[1, 2.1, "a"], [2, 3.1, "b"]], columns=list("abc"))
test_data.to_sql(
name="test_public_schema",
con=conn,
if_exists="append",
index=False,
schema="public",
)

df_out = sql.read_sql_table("test_public_schema", conn, schema="public")
tm.assert_frame_equal(test_data, df_out)


@pytest.mark.parametrize("conn", mysql_connectable)
def test_insertion_method_on_conflict_update(conn, request):
# GH 14553: Example in to_sql docstring
Expand Down

0 comments on commit 5eecbd0

Please sign in to comment.