From 7d0c35895d88646e010f6ef16233422fd35721f4 Mon Sep 17 00:00:00 2001 From: RajatS Mukherjee Date: Fri, 18 Aug 2023 19:37:06 +0000 Subject: [PATCH 1/5] deprecated nonkeyword arguments --- doc/source/whatsnew/v2.2.0.rst | 1 + pandas/core/frame.py | 3 +++ pandas/tests/io/test_parquet.py | 12 ++++++++++++ 3 files changed, 16 insertions(+) diff --git a/doc/source/whatsnew/v2.2.0.rst b/doc/source/whatsnew/v2.2.0.rst index b90563ba43d83..55b00c9acd82a 100644 --- a/doc/source/whatsnew/v2.2.0.rst +++ b/doc/source/whatsnew/v2.2.0.rst @@ -96,6 +96,7 @@ Deprecations - Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_json` except ``path_or_buf``. (:issue:`54229`) - Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_latex` except ``buf``. (:issue:`54229`) - Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_markdown` except ``buf``. (:issue:`54229`) +- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_parquet` except ``path``. (:issue:`54229`) - Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_pickle` except ``path``. (:issue:`54229`) - Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_string` except ``buf``. (:issue:`54229`) - diff --git a/pandas/core/frame.py b/pandas/core/frame.py index c2a3d9285386e..b4c73cdd92e8b 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -2878,6 +2878,9 @@ def to_parquet( ) -> None: ... + @deprecate_nonkeyword_arguments( + version="3.0", allowed_args=["self", "path"], name="to_parquet" + ) @doc(storage_options=_shared_docs["storage_options"]) def to_parquet( self, diff --git a/pandas/tests/io/test_parquet.py b/pandas/tests/io/test_parquet.py index fcc1c218a149d..a3c88b694cd77 100644 --- a/pandas/tests/io/test_parquet.py +++ b/pandas/tests/io/test_parquet.py @@ -359,6 +359,18 @@ def test_cross_engine_fp_pa(df_cross_compat, pa, fp): tm.assert_frame_equal(result, df[["a", "d"]]) +def test_parquet_pos_args_deprecation(): + # GH-54229 + df = pd.DataFrame({"a": [1, 2, 3]}) + msg = ( + r"Starting with pandas version 3.0 all arguments of to_parquet except for the " + r"argument 'path' will be keyword-only." + ) + with tm.assert_produces_warning(FutureWarning, match=msg): + buffer = BytesIO() + df.to_parquet(buffer, "auto") + + class Base: def check_error_on_write(self, df, engine, exc, err_msg): # check that we are raising the exception on writing From 4ad606d9e319c922991a2b0924a37fc43bd9da3e Mon Sep 17 00:00:00 2001 From: RajatS Mukherjee Date: Fri, 18 Aug 2023 20:28:47 +0000 Subject: [PATCH 2/5] fixed errors in test --- pandas/tests/io/test_parquet.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/tests/io/test_parquet.py b/pandas/tests/io/test_parquet.py index a3c88b694cd77..632f6358ab73c 100644 --- a/pandas/tests/io/test_parquet.py +++ b/pandas/tests/io/test_parquet.py @@ -1016,7 +1016,7 @@ def test_filter_row_groups(self, pa): pytest.importorskip("pyarrow") df = pd.DataFrame({"a": list(range(0, 3))}) with tm.ensure_clean() as path: - df.to_parquet(path, pa) + df.to_parquet(path, engine=pa) result = read_parquet( path, pa, filters=[("a", "==", 0)], use_legacy_dataset=False ) @@ -1029,7 +1029,7 @@ def test_read_parquet_manager(self, pa, using_array_manager): ) with tm.ensure_clean() as path: - df.to_parquet(path, pa) + df.to_parquet(path, engine=pa) result = read_parquet(path, pa) if using_array_manager: assert isinstance(result._mgr, pd.core.internals.ArrayManager) @@ -1195,7 +1195,7 @@ def test_filter_row_groups(self, fp): d = {"a": list(range(0, 3))} df = pd.DataFrame(d) with tm.ensure_clean() as path: - df.to_parquet(path, fp, compression=None, row_group_offsets=1) + df.to_parquet(path, engine=fp, compression=None, row_group_offsets=1) result = read_parquet(path, fp, filters=[("a", "==", 0)]) assert len(result) == 1 From 47922666a4954c34b712b84b197444c1e5242950 Mon Sep 17 00:00:00 2001 From: RajatS Mukherjee Date: Mon, 21 Aug 2023 18:33:28 +0000 Subject: [PATCH 3/5] added check_stacklevel for test --- pandas/tests/io/test_parquet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/io/test_parquet.py b/pandas/tests/io/test_parquet.py index 632f6358ab73c..6d44b7234df42 100644 --- a/pandas/tests/io/test_parquet.py +++ b/pandas/tests/io/test_parquet.py @@ -366,7 +366,7 @@ def test_parquet_pos_args_deprecation(): r"Starting with pandas version 3.0 all arguments of to_parquet except for the " r"argument 'path' will be keyword-only." ) - with tm.assert_produces_warning(FutureWarning, match=msg): + with tm.assert_produces_warning(FutureWarning, match=msg, check_stacklevel=False): buffer = BytesIO() df.to_parquet(buffer, "auto") From c7d4fe660e65f483f552b16c00c104ad52520520 Mon Sep 17 00:00:00 2001 From: RajatS Mukherjee Date: Tue, 22 Aug 2023 06:33:24 +0000 Subject: [PATCH 4/5] added engine param --- pandas/tests/io/test_parquet.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/io/test_parquet.py b/pandas/tests/io/test_parquet.py index 3192ebc2be12a..bc67c36294964 100644 --- a/pandas/tests/io/test_parquet.py +++ b/pandas/tests/io/test_parquet.py @@ -359,7 +359,7 @@ def test_cross_engine_fp_pa(df_cross_compat, pa, fp): tm.assert_frame_equal(result, df[["a", "d"]]) -def test_parquet_pos_args_deprecation(): +def test_parquet_pos_args_deprecation(engine): # GH-54229 df = pd.DataFrame({"a": [1, 2, 3]}) msg = ( @@ -368,7 +368,7 @@ def test_parquet_pos_args_deprecation(): ) with tm.assert_produces_warning(FutureWarning, match=msg, check_stacklevel=False): buffer = BytesIO() - df.to_parquet(buffer, "auto") + df.to_parquet(buffer, engine) class Base: From 5673a7a2b998d9b3c34d2c855fbf7002a0a831b4 Mon Sep 17 00:00:00 2001 From: RajatS Mukherjee Date: Tue, 22 Aug 2023 09:20:54 +0000 Subject: [PATCH 5/5] updated test --- pandas/tests/io/test_parquet.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pandas/tests/io/test_parquet.py b/pandas/tests/io/test_parquet.py index bc67c36294964..9182e4c4e7674 100644 --- a/pandas/tests/io/test_parquet.py +++ b/pandas/tests/io/test_parquet.py @@ -366,9 +366,11 @@ def test_parquet_pos_args_deprecation(engine): r"Starting with pandas version 3.0 all arguments of to_parquet except for the " r"argument 'path' will be keyword-only." ) - with tm.assert_produces_warning(FutureWarning, match=msg, check_stacklevel=False): - buffer = BytesIO() - df.to_parquet(buffer, engine) + with tm.ensure_clean() as path: + with tm.assert_produces_warning( + FutureWarning, match=msg, check_stacklevel=False + ): + df.to_parquet(path, engine) class Base: