Skip to content

Commit

Permalink
57539: Fixed creation unnamed table when using public schema
Browse files Browse the repository at this point in the history
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
  • Loading branch information
shabab477 committed Mar 27, 2024
1 parent b552dc9 commit 6bb2eb8
Show file tree
Hide file tree
Showing 3 changed files with 21 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 @@ -24,6 +24,7 @@ Bug fixes
~~~~~~~~~
- :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 @@ -2380,7 +2380,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
17 changes: 17 additions & 0 deletions pandas/tests/io/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -1373,6 +1373,23 @@ def insert_on_conflict(table, conn, keys, data_iter):
pandasSQL.drop_table("test_insert_conflict")


@pytest.mark.parametrize("conn", postgresql_adbc_conn)
def test_to_sql_on_public_schema(conn, request):
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")
assert test_data.equals(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 6bb2eb8

Please sign in to comment.