From 78f1173b04acb16971f67cd17da405e4525765ab Mon Sep 17 00:00:00 2001 From: RajatS Mukherjee Date: Fri, 18 Aug 2023 20:02:23 +0000 Subject: [PATCH 1/6] made arguments keyword only --- pandas/core/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 7da41b890598d..381a65b0754a0 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -3099,7 +3099,7 @@ def to_pickle( @final def to_clipboard( - self, excel: bool_t = True, sep: str | None = None, **kwargs + self, *, excel: bool_t = True, sep: str | None = None, **kwargs ) -> None: r""" Copy object to the system clipboard. From d463dfa39b8688bf41a338c30393fac39e6581fb Mon Sep 17 00:00:00 2001 From: RajatS Mukherjee Date: Sat, 19 Aug 2023 08:59:37 +0000 Subject: [PATCH 2/6] added whatsnew --- doc/source/whatsnew/v2.2.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v2.2.0.rst b/doc/source/whatsnew/v2.2.0.rst index b90563ba43d83..3543935975bc7 100644 --- a/doc/source/whatsnew/v2.2.0.rst +++ b/doc/source/whatsnew/v2.2.0.rst @@ -92,6 +92,7 @@ Other API changes Deprecations ~~~~~~~~~~~~ +- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_clipboard`. (: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_json` except ``path_or_buf``. (:issue:`54229`) - Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_latex` except ``buf``. (:issue:`54229`) From 715e4b8a29d5b5ab18e207d48111a5dd06af9a02 Mon Sep 17 00:00:00 2001 From: RajatS Mukherjee Date: Mon, 21 Aug 2023 19:14:26 +0000 Subject: [PATCH 3/6] deprecated nonkeyword arguments --- pandas/core/generic.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 381a65b0754a0..13c4d3824d860 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -3098,6 +3098,7 @@ def to_pickle( ) @final + @deprecate_nonkeyword_arguments(version="3.0", allowed_args=["self"], name="to_csv") def to_clipboard( self, *, excel: bool_t = True, sep: str | None = None, **kwargs ) -> None: From 8219a8cd674d8e22ddfadc815e7e358c405099a0 Mon Sep 17 00:00:00 2001 From: RajatS Mukherjee Date: Mon, 21 Aug 2023 19:16:17 +0000 Subject: [PATCH 4/6] corrected typo --- pandas/core/generic.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 13c4d3824d860..814234cec9b33 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -3098,7 +3098,9 @@ def to_pickle( ) @final - @deprecate_nonkeyword_arguments(version="3.0", allowed_args=["self"], name="to_csv") + @deprecate_nonkeyword_arguments( + version="3.0", allowed_args=["self"], name="to_clipboard" + ) def to_clipboard( self, *, excel: bool_t = True, sep: str | None = None, **kwargs ) -> None: From e33cd8b1f1acac02a444bbee32610c9a4336d426 Mon Sep 17 00:00:00 2001 From: Rajat Subhra Mukherjee Date: Tue, 22 Aug 2023 00:53:56 +0530 Subject: [PATCH 5/6] Update pandas/core/generic.py Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> --- pandas/core/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 814234cec9b33..6d4bd260b9d80 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -3102,7 +3102,7 @@ def to_pickle( version="3.0", allowed_args=["self"], name="to_clipboard" ) def to_clipboard( - self, *, excel: bool_t = True, sep: str | None = None, **kwargs + self, excel: bool_t = True, sep: str | None = None, **kwargs ) -> None: r""" Copy object to the system clipboard. From 48c696ae829282e17d6fee3606c0712ba4cbb006 Mon Sep 17 00:00:00 2001 From: RajatS Mukherjee Date: Mon, 21 Aug 2023 19:25:36 +0000 Subject: [PATCH 6/6] added test --- pandas/tests/io/test_clipboard.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pandas/tests/io/test_clipboard.py b/pandas/tests/io/test_clipboard.py index 4b3c82ad3f083..10e0467c5d74d 100644 --- a/pandas/tests/io/test_clipboard.py +++ b/pandas/tests/io/test_clipboard.py @@ -471,3 +471,13 @@ def test_invalid_dtype_backend(self): ) with pytest.raises(ValueError, match=msg): read_clipboard(dtype_backend="numpy") + + def test_to_clipboard_pos_args_deprecation(self): + # GH-54229 + df = DataFrame({"a": [1, 2, 3]}) + msg = ( + r"Starting with pandas version 3.0 all arguments of to_clipboard " + r"will be keyword-only." + ) + with tm.assert_produces_warning(FutureWarning, match=msg): + df.to_clipboard(True, None)