Skip to content

TYP: to_csv accepts IO[bytes] and fix FilePathOrBuffer #41903

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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