Skip to content

Commit

Permalink
DEPR: deprecated nonkeyword arguments in to_csv (#54632)
Browse files Browse the repository at this point in the history
deprecated nonkeyword arguments
  • Loading branch information
rsm-23 authored Aug 21, 2023
1 parent 61e54c2 commit 43691a2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.2.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ Other API changes

Deprecations
~~~~~~~~~~~~
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_csv` except ``path_or_buf``. (:issue:`54229`)
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_hdf` except ``path_or_buf``. (:issue:`54229`)
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_html` except ``buf``. (:issue:`54229`)
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_json` except ``path_or_buf``. (:issue:`54229`)
Expand Down
3 changes: 3 additions & 0 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3728,6 +3728,9 @@ def to_csv(
...

@final
@deprecate_nonkeyword_arguments(
version="3.0", allowed_args=["self", "path_or_buf"], name="to_csv"
)
@doc(
storage_options=_shared_docs["storage_options"],
compression_options=_shared_docs["compression_options"] % "path_or_buf",
Expand Down
12 changes: 12 additions & 0 deletions pandas/tests/io/formats/test_to_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,3 +731,15 @@ def test_to_csv_iterative_compression_buffer(compression):
pd.read_csv(buffer, compression=compression, index_col=0), df
)
assert not buffer.closed


def test_to_csv_pos_args_deprecation():
# GH-54229
df = DataFrame({"a": [1, 2, 3]})
msg = (
r"Starting with pandas version 3.0 all arguments of to_csv except for the "
r"argument 'path_or_buf' will be keyword-only."
)
with tm.assert_produces_warning(FutureWarning, match=msg):
buffer = io.BytesIO()
df.to_csv(buffer, ";")

0 comments on commit 43691a2

Please sign in to comment.