Skip to content

Commit

Permalink
TYP: to_csv accepts IO[bytes] and fix FilePathOrBuffer (#41903)
Browse files Browse the repository at this point in the history
  • Loading branch information
twoertwein authored Jun 10, 2021
1 parent 9ef6e9c commit 4d549cb
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions pandas/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@

# filenames and file-like-objects
Buffer = Union[IO[AnyStr], RawIOBase, BufferedIOBase, TextIOBase, TextIOWrapper, mmap]
FileOrBuffer = Union[str, Buffer[T]]
FilePathOrBuffer = Union["PathLike[str]", FileOrBuffer[T]]
FileOrBuffer = Union[str, Buffer[AnyStr]]
FilePathOrBuffer = Union["PathLike[str]", FileOrBuffer[AnyStr]]

# for arbitrary kwargs passed during reading/writing files
StorageOptions = Optional[Dict[str, Any]]
Expand Down
3 changes: 2 additions & 1 deletion pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from typing import (
TYPE_CHECKING,
Any,
AnyStr,
Callable,
Hashable,
Mapping,
Expand Down Expand Up @@ -3295,7 +3296,7 @@ def to_latex(
@doc(storage_options=_shared_docs["storage_options"])
def to_csv(
self,
path_or_buf: FilePathOrBuffer | None = None,
path_or_buf: FilePathOrBuffer[AnyStr] | None = None,
sep: str = ",",
na_rep: str = "",
float_format: str | None = None,
Expand Down
3 changes: 2 additions & 1 deletion pandas/io/formats/csvs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from typing import (
TYPE_CHECKING,
Any,
AnyStr,
Hashable,
Iterator,
Sequence,
Expand Down Expand Up @@ -48,7 +49,7 @@ class CSVFormatter:
def __init__(
self,
formatter: DataFrameFormatter,
path_or_buf: FilePathOrBuffer[str] = "",
path_or_buf: FilePathOrBuffer[AnyStr] = "",
sep: str = ",",
cols: Sequence[Hashable] | None = None,
index_label: IndexLabel | None = None,
Expand Down
3 changes: 2 additions & 1 deletion pandas/io/formats/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
IO,
TYPE_CHECKING,
Any,
AnyStr,
Callable,
Hashable,
Iterable,
Expand Down Expand Up @@ -1054,7 +1055,7 @@ def to_string(

def to_csv(
self,
path_or_buf: FilePathOrBuffer[str] | None = None,
path_or_buf: FilePathOrBuffer[AnyStr] | None = None,
encoding: str | None = None,
sep: str = ",",
columns: Sequence[Hashable] | None = None,
Expand Down

0 comments on commit 4d549cb

Please sign in to comment.