Skip to content

Commit 43691a2

Browse files
authored
DEPR: deprecated nonkeyword arguments in to_csv (#54632)
deprecated nonkeyword arguments
1 parent 61e54c2 commit 43691a2

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

doc/source/whatsnew/v2.2.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ Other API changes
9292

9393
Deprecations
9494
~~~~~~~~~~~~
95+
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_csv` except ``path_or_buf``. (:issue:`54229`)
9596
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_hdf` except ``path_or_buf``. (:issue:`54229`)
9697
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_html` except ``buf``. (:issue:`54229`)
9798
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_json` except ``path_or_buf``. (:issue:`54229`)

pandas/core/generic.py

+3
Original file line numberDiff line numberDiff line change
@@ -3728,6 +3728,9 @@ def to_csv(
37283728
...
37293729

37303730
@final
3731+
@deprecate_nonkeyword_arguments(
3732+
version="3.0", allowed_args=["self", "path_or_buf"], name="to_csv"
3733+
)
37313734
@doc(
37323735
storage_options=_shared_docs["storage_options"],
37333736
compression_options=_shared_docs["compression_options"] % "path_or_buf",

pandas/tests/io/formats/test_to_csv.py

+12
Original file line numberDiff line numberDiff line change
@@ -731,3 +731,15 @@ def test_to_csv_iterative_compression_buffer(compression):
731731
pd.read_csv(buffer, compression=compression, index_col=0), df
732732
)
733733
assert not buffer.closed
734+
735+
736+
def test_to_csv_pos_args_deprecation():
737+
# GH-54229
738+
df = DataFrame({"a": [1, 2, 3]})
739+
msg = (
740+
r"Starting with pandas version 3.0 all arguments of to_csv except for the "
741+
r"argument 'path_or_buf' will be keyword-only."
742+
)
743+
with tm.assert_produces_warning(FutureWarning, match=msg):
744+
buffer = io.BytesIO()
745+
df.to_csv(buffer, ";")

0 commit comments

Comments
 (0)