From e03a602e036820a88f7ddab739308d0689e8c65e Mon Sep 17 00:00:00 2001 From: yangdanny97 Date: Fri, 18 Apr 2025 09:45:06 -0400 Subject: [PATCH 1/3] type to_clipboard kwargs to match to_csv --- pandas-stubs/core/frame.pyi | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/pandas-stubs/core/frame.pyi b/pandas-stubs/core/frame.pyi index cbaa3096d..6cde88ed3 100644 --- a/pandas-stubs/core/frame.pyi +++ b/pandas-stubs/core/frame.pyi @@ -2230,7 +2230,27 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack): self, excel: _bool = ..., sep: _str | None = ..., - **kwargs: Any, # TODO: make more precise https://github.com/pandas-dev/pandas-stubs/issues/1174 + *, + path_or_buf: FilePath | WriteBuffer[bytes] | WriteBuffer[str], + na_rep: _str = ..., + float_format: _str | Callable[[object], _str] | None = ..., + columns: list[HashableT1] | None = ..., + header: _bool | list[_str] = ..., + index: _bool = ..., + index_label: Literal[False] | _str | list[HashableT2] | None = ..., + mode: FileWriteMode = ..., + encoding: _str | None = ..., + compression: CompressionOptions = ..., + quoting: CSVQuoting = ..., + quotechar: _str = ..., + lineterminator: _str | None = ..., + chunksize: int | None = ..., + date_format: _str | None = ..., + doublequote: _bool = ..., + escapechar: _str | None = ..., + decimal: _str = ..., + errors: _str = ..., + storage_options: StorageOptions = ..., ) -> None: ... @overload def to_json( From 1d66fa842368af0f9a957cc4c331670c7330bf9e Mon Sep 17 00:00:00 2001 From: yangdanny97 Date: Tue, 22 Apr 2025 21:36:25 +0800 Subject: [PATCH 2/3] set defaults and fix imports --- pandas-stubs/core/frame.pyi | 46 +++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/pandas-stubs/core/frame.pyi b/pandas-stubs/core/frame.pyi index 6cde88ed3..625d7b6ab 100644 --- a/pandas-stubs/core/frame.pyi +++ b/pandas-stubs/core/frame.pyi @@ -83,8 +83,10 @@ from pandas._typing import ( CalculationMethod, ColspaceArgType, CompressionOptions, + CSVQuoting, Dtype, FilePath, + FileWriteMode, FillnaOptions, FormattersType, Frequency, @@ -2228,29 +2230,29 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack): def take(self, indices: list, axis: Axis = ..., **kwargs: Any) -> Self: ... def to_clipboard( self, - excel: _bool = ..., - sep: _str | None = ..., - *, - path_or_buf: FilePath | WriteBuffer[bytes] | WriteBuffer[str], - na_rep: _str = ..., - float_format: _str | Callable[[object], _str] | None = ..., - columns: list[HashableT1] | None = ..., - header: _bool | list[_str] = ..., - index: _bool = ..., - index_label: Literal[False] | _str | list[HashableT2] | None = ..., - mode: FileWriteMode = ..., - encoding: _str | None = ..., - compression: CompressionOptions = ..., + excel: _bool = True, + sep: _str | None = None, + *, + path_or_buf: FilePath | WriteBuffer[bytes] | WriteBuffer[str] | None = None, + na_rep: _str = "", + float_format: _str | Callable[[object], _str] | None = None, + columns: list[HashableT1] | None = None, + header: _bool | list[_str] = True, + index: _bool = True, + index_label: Literal[False] | _str | list[HashableT2] | None = None, + mode: FileWriteMode = "w", + encoding: _str | None = None, + compression: CompressionOptions = "infer", quoting: CSVQuoting = ..., - quotechar: _str = ..., - lineterminator: _str | None = ..., - chunksize: int | None = ..., - date_format: _str | None = ..., - doublequote: _bool = ..., - escapechar: _str | None = ..., - decimal: _str = ..., - errors: _str = ..., - storage_options: StorageOptions = ..., + quotechar: _str = '"', + lineterminator: _str | None = None, + chunksize: int | None = None, + date_format: _str | None = None, + doublequote: _bool = True, + escapechar: _str | None = None, + decimal: _str = ".", + errors: _str = "strict", + storage_options: StorageOptions = None, ) -> None: ... @overload def to_json( From 5d2b7f2ef9e24c01438fcc9f407c1b7a4ecdce28 Mon Sep 17 00:00:00 2001 From: yangdanny97 Date: Wed, 23 Apr 2025 21:02:18 +0800 Subject: [PATCH 3/3] movekwargs to generic.pyi, add tests, remove frame.pyi definition --- pandas-stubs/core/frame.pyi | 28 ---------------------------- pandas-stubs/core/generic.pyi | 24 +++++++++++++++++++++++- tests/test_io.py | 3 +++ 3 files changed, 26 insertions(+), 29 deletions(-) diff --git a/pandas-stubs/core/frame.pyi b/pandas-stubs/core/frame.pyi index 625d7b6ab..5ae96b0da 100644 --- a/pandas-stubs/core/frame.pyi +++ b/pandas-stubs/core/frame.pyi @@ -83,10 +83,8 @@ from pandas._typing import ( CalculationMethod, ColspaceArgType, CompressionOptions, - CSVQuoting, Dtype, FilePath, - FileWriteMode, FillnaOptions, FormattersType, Frequency, @@ -2228,32 +2226,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack): def swapaxes(self, axis1: Axis, axis2: Axis, copy: _bool = ...) -> Self: ... def tail(self, n: int = ...) -> Self: ... def take(self, indices: list, axis: Axis = ..., **kwargs: Any) -> Self: ... - def to_clipboard( - self, - excel: _bool = True, - sep: _str | None = None, - *, - path_or_buf: FilePath | WriteBuffer[bytes] | WriteBuffer[str] | None = None, - na_rep: _str = "", - float_format: _str | Callable[[object], _str] | None = None, - columns: list[HashableT1] | None = None, - header: _bool | list[_str] = True, - index: _bool = True, - index_label: Literal[False] | _str | list[HashableT2] | None = None, - mode: FileWriteMode = "w", - encoding: _str | None = None, - compression: CompressionOptions = "infer", - quoting: CSVQuoting = ..., - quotechar: _str = '"', - lineterminator: _str | None = None, - chunksize: int | None = None, - date_format: _str | None = None, - doublequote: _bool = True, - escapechar: _str | None = None, - decimal: _str = ".", - errors: _str = "strict", - storage_options: StorageOptions = None, - ) -> None: ... @overload def to_json( self, diff --git a/pandas-stubs/core/generic.pyi b/pandas-stubs/core/generic.pyi index 0c432b86b..456d0697c 100644 --- a/pandas-stubs/core/generic.pyi +++ b/pandas-stubs/core/generic.pyi @@ -179,7 +179,29 @@ class NDFrame(indexing.IndexingMixin): storage_options: StorageOptions = ..., ) -> None: ... def to_clipboard( - self, excel: _bool = ..., sep: _str | None = ..., **kwargs + self, + excel: _bool = ..., + sep: _str | None = ..., + *, + na_rep: _str = ..., + float_format: _str | Callable[[object], _str] | None = ..., + columns: list[HashableT1] | None = ..., + header: _bool | list[_str] = ..., + index: _bool = ..., + index_label: Literal[False] | _str | list[HashableT2] | None = ..., + mode: FileWriteMode = ..., + encoding: _str | None = ..., + compression: CompressionOptions = ..., + quoting: CSVQuoting = ..., + quotechar: _str = ..., + lineterminator: _str | None = ..., + chunksize: int | None = ..., + date_format: _str | None = ..., + doublequote: _bool = ..., + escapechar: _str | None = ..., + decimal: _str = ..., + errors: _str = ..., + storage_options: StorageOptions = ..., ) -> None: ... @overload def to_latex( diff --git a/tests/test_io.py b/tests/test_io.py index 0397629ee..97d090c73 100644 --- a/tests/test_io.py +++ b/tests/test_io.py @@ -275,6 +275,9 @@ def test_clipboard(): ), DataFrame, ) + # Passing kwargs for to_csv + DF.to_clipboard(quoting=csv.QUOTE_ALL) + DF.to_clipboard(sep=",", index=False) if TYPE_CHECKING_INVALID_USAGE: pd.read_clipboard(names="abcd") # type: ignore[call-overload] # pyright: ignore[reportArgumentType] pd.read_clipboard(usecols="abcd") # type: ignore[call-overload] # pyright: ignore[reportArgumentType]