Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEPR: Positional arguments in to_sql except name #54397

Merged
merged 16 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v2.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ Other enhancements
- Reductions :meth:`Series.argmax`, :meth:`Series.argmin`, :meth:`Series.idxmax`, :meth:`Series.idxmin`, :meth:`Index.argmax`, :meth:`Index.argmin`, :meth:`DataFrame.idxmax`, :meth:`DataFrame.idxmin` are now supported for object-dtype objects (:issue:`4279`, :issue:`18021`, :issue:`40685`, :issue:`43697`)
- :meth:`DataFrame.to_parquet` and :func:`read_parquet` will now write and read ``attrs`` respectively (:issue:`54346`)
- Performance improvement in :meth:`GroupBy.quantile` (:issue:`51722`)
- Updated ``con`` parameter for :meth:`DataFrame.to_sql` to be a keyword argument. (:issue:`54229`)
mroeschke marked this conversation as resolved.
Show resolved Hide resolved
-

.. ---------------------------------------------------------------------------
.. _whatsnew_210.notable_bug_fixes:
Expand Down
12 changes: 9 additions & 3 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@
Mapping,
Sequence,
)
import sqlite3

import sqlalchemy

from pandas._libs.tslibs import BaseOffset

Expand Down Expand Up @@ -2795,7 +2798,10 @@ def to_hdf(
def to_sql(
self,
name: str,
con,
con: sqlalchemy.engine.Engine
mroeschke marked this conversation as resolved.
Show resolved Hide resolved
| sqlalchemy.engine.Connection
| sqlite3.Connection
| None = None,
schema: str | None = None,
if_exists: Literal["fail", "replace", "append"] = "fail",
index: bool_t = True,
Expand Down Expand Up @@ -2956,7 +2962,7 @@ def to_sql(
... stmt = insert(table.table).values(data).on_conflict_do_nothing(index_elements=["a"])
... result = conn.execute(stmt)
... return result.rowcount
>>> df_conflict.to_sql("conflict_table", conn, if_exists="append", method=insert_on_conflict_nothing) # doctest: +SKIP
>>> df_conflict.to_sql("conflict_table", con=conn, if_exists="append", method=insert_on_conflict_nothing) # doctest: +SKIP
0

For MySQL, a callable to update columns ``b`` and ``c`` if there's a conflict
Expand All @@ -2973,7 +2979,7 @@ def to_sql(
... stmt = stmt.on_duplicate_key_update(b=stmt.inserted.b, c=stmt.inserted.c)
... result = conn.execute(stmt)
... return result.rowcount
>>> df_conflict.to_sql("conflict_table", conn, if_exists="append", method=insert_on_conflict_update) # doctest: +SKIP
>>> df_conflict.to_sql("conflict_table", con=conn, if_exists="append", method=insert_on_conflict_update) # doctest: +SKIP
2

Specify the dtype (especially useful for integers with missing values).
Expand Down
Loading