Skip to content

Commit 75273f1

Browse files
authored
GH1174 more precise kwargs in DataFrame.to_clipboard (#1195)
* type to_clipboard kwargs to match to_csv * set defaults and fix imports * movekwargs to generic.pyi, add tests, remove frame.pyi definition
1 parent e4ee5b3 commit 75273f1

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

pandas-stubs/core/frame.pyi

-6
Original file line numberDiff line numberDiff line change
@@ -2226,12 +2226,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
22262226
def swapaxes(self, axis1: Axis, axis2: Axis, copy: _bool = ...) -> Self: ...
22272227
def tail(self, n: int = ...) -> Self: ...
22282228
def take(self, indices: list, axis: Axis = ..., **kwargs: Any) -> Self: ...
2229-
def to_clipboard(
2230-
self,
2231-
excel: _bool = ...,
2232-
sep: _str | None = ...,
2233-
**kwargs: Any, # TODO: make more precise https://github.com/pandas-dev/pandas-stubs/issues/1174
2234-
) -> None: ...
22352229
@overload
22362230
def to_json(
22372231
self,

pandas-stubs/core/generic.pyi

+23-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,29 @@ class NDFrame(indexing.IndexingMixin):
179179
storage_options: StorageOptions = ...,
180180
) -> None: ...
181181
def to_clipboard(
182-
self, excel: _bool = ..., sep: _str | None = ..., **kwargs
182+
self,
183+
excel: _bool = ...,
184+
sep: _str | None = ...,
185+
*,
186+
na_rep: _str = ...,
187+
float_format: _str | Callable[[object], _str] | None = ...,
188+
columns: list[HashableT1] | None = ...,
189+
header: _bool | list[_str] = ...,
190+
index: _bool = ...,
191+
index_label: Literal[False] | _str | list[HashableT2] | None = ...,
192+
mode: FileWriteMode = ...,
193+
encoding: _str | None = ...,
194+
compression: CompressionOptions = ...,
195+
quoting: CSVQuoting = ...,
196+
quotechar: _str = ...,
197+
lineterminator: _str | None = ...,
198+
chunksize: int | None = ...,
199+
date_format: _str | None = ...,
200+
doublequote: _bool = ...,
201+
escapechar: _str | None = ...,
202+
decimal: _str = ...,
203+
errors: _str = ...,
204+
storage_options: StorageOptions = ...,
183205
) -> None: ...
184206
@overload
185207
def to_latex(

tests/test_io.py

+3
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,9 @@ def test_clipboard():
275275
),
276276
DataFrame,
277277
)
278+
# Passing kwargs for to_csv
279+
DF.to_clipboard(quoting=csv.QUOTE_ALL)
280+
DF.to_clipboard(sep=",", index=False)
278281
if TYPE_CHECKING_INVALID_USAGE:
279282
pd.read_clipboard(names="abcd") # type: ignore[call-overload] # pyright: ignore[reportArgumentType]
280283
pd.read_clipboard(usecols="abcd") # type: ignore[call-overload] # pyright: ignore[reportArgumentType]

0 commit comments

Comments
 (0)