Skip to content

Commit 0fc36ad

Browse files
authored
DEPR: deprecated nonkeyword arguments in to_parquet (#54631)
* deprecated nonkeyword arguments * fixed errors in test * added check_stacklevel for test * added engine param * updated test
1 parent 3e58233 commit 0fc36ad

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

doc/source/whatsnew/v2.2.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ Deprecations
9898
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_json` except ``path_or_buf``. (:issue:`54229`)
9999
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_latex` except ``buf``. (:issue:`54229`)
100100
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_markdown` except ``buf``. (:issue:`54229`)
101+
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_parquet` except ``path``. (:issue:`54229`)
101102
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_pickle` except ``path``. (:issue:`54229`)
102103
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_string` except ``buf``. (:issue:`54229`)
103104
- Deprecated not passing a tuple to :class:`DataFrameGroupBy.get_group` or :class:`SeriesGroupBy.get_group` when grouping by a length-1 list-like (:issue:`25971`)

pandas/core/frame.py

+3
Original file line numberDiff line numberDiff line change
@@ -2878,6 +2878,9 @@ def to_parquet(
28782878
) -> None:
28792879
...
28802880

2881+
@deprecate_nonkeyword_arguments(
2882+
version="3.0", allowed_args=["self", "path"], name="to_parquet"
2883+
)
28812884
@doc(storage_options=_shared_docs["storage_options"])
28822885
def to_parquet(
28832886
self,

pandas/tests/io/test_parquet.py

+17-3
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,20 @@ def test_cross_engine_fp_pa(df_cross_compat, pa, fp):
359359
tm.assert_frame_equal(result, df[["a", "d"]])
360360

361361

362+
def test_parquet_pos_args_deprecation(engine):
363+
# GH-54229
364+
df = pd.DataFrame({"a": [1, 2, 3]})
365+
msg = (
366+
r"Starting with pandas version 3.0 all arguments of to_parquet except for the "
367+
r"argument 'path' will be keyword-only."
368+
)
369+
with tm.ensure_clean() as path:
370+
with tm.assert_produces_warning(
371+
FutureWarning, match=msg, check_stacklevel=False
372+
):
373+
df.to_parquet(path, engine)
374+
375+
362376
class Base:
363377
def check_error_on_write(self, df, engine, exc, err_msg):
364378
# check that we are raising the exception on writing
@@ -998,7 +1012,7 @@ def test_filter_row_groups(self, pa):
9981012
pytest.importorskip("pyarrow")
9991013
df = pd.DataFrame({"a": list(range(0, 3))})
10001014
with tm.ensure_clean() as path:
1001-
df.to_parquet(path, pa)
1015+
df.to_parquet(path, engine=pa)
10021016
result = read_parquet(
10031017
path, pa, filters=[("a", "==", 0)], use_legacy_dataset=False
10041018
)
@@ -1011,7 +1025,7 @@ def test_read_parquet_manager(self, pa, using_array_manager):
10111025
)
10121026

10131027
with tm.ensure_clean() as path:
1014-
df.to_parquet(path, pa)
1028+
df.to_parquet(path, engine=pa)
10151029
result = read_parquet(path, pa)
10161030
if using_array_manager:
10171031
assert isinstance(result._mgr, pd.core.internals.ArrayManager)
@@ -1177,7 +1191,7 @@ def test_filter_row_groups(self, fp):
11771191
d = {"a": list(range(0, 3))}
11781192
df = pd.DataFrame(d)
11791193
with tm.ensure_clean() as path:
1180-
df.to_parquet(path, fp, compression=None, row_group_offsets=1)
1194+
df.to_parquet(path, engine=fp, compression=None, row_group_offsets=1)
11811195
result = read_parquet(path, fp, filters=[("a", "==", 0)])
11821196
assert len(result) == 1
11831197

0 commit comments

Comments
 (0)