Skip to content

Commit fd25a3e

Browse files
twoertweinJulianWgs
authored andcommitted
TYP: to_csv accepts IO[bytes] and fix FilePathOrBuffer (pandas-dev#41903)
1 parent 1bf6c88 commit fd25a3e

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

pandas/_typing.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@
170170

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

176176
# for arbitrary kwargs passed during reading/writing files
177177
StorageOptions = Optional[Dict[str, Any]]

pandas/core/generic.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from typing import (
1212
TYPE_CHECKING,
1313
Any,
14+
AnyStr,
1415
Callable,
1516
Hashable,
1617
Mapping,
@@ -3295,7 +3296,7 @@ def to_latex(
32953296
@doc(storage_options=_shared_docs["storage_options"])
32963297
def to_csv(
32973298
self,
3298-
path_or_buf: FilePathOrBuffer | None = None,
3299+
path_or_buf: FilePathOrBuffer[AnyStr] | None = None,
32993300
sep: str = ",",
33003301
na_rep: str = "",
33013302
float_format: str | None = None,

pandas/io/formats/csvs.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from typing import (
1010
TYPE_CHECKING,
1111
Any,
12+
AnyStr,
1213
Hashable,
1314
Iterator,
1415
Sequence,
@@ -48,7 +49,7 @@ class CSVFormatter:
4849
def __init__(
4950
self,
5051
formatter: DataFrameFormatter,
51-
path_or_buf: FilePathOrBuffer[str] = "",
52+
path_or_buf: FilePathOrBuffer[AnyStr] = "",
5253
sep: str = ",",
5354
cols: Sequence[Hashable] | None = None,
5455
index_label: IndexLabel | None = None,

pandas/io/formats/format.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
IO,
2020
TYPE_CHECKING,
2121
Any,
22+
AnyStr,
2223
Callable,
2324
Hashable,
2425
Iterable,
@@ -1054,7 +1055,7 @@ def to_string(
10541055

10551056
def to_csv(
10561057
self,
1057-
path_or_buf: FilePathOrBuffer[str] | None = None,
1058+
path_or_buf: FilePathOrBuffer[AnyStr] | None = None,
10581059
encoding: str | None = None,
10591060
sep: str = ",",
10601061
columns: Sequence[Hashable] | None = None,

0 commit comments

Comments
 (0)