Skip to content

Commit e5f8bc6

Browse files
committed
ENH: Improve read_{csv/fwf/table}
1 parent 15447ae commit e5f8bc6

File tree

7 files changed

+346
-462
lines changed

7 files changed

+346
-462
lines changed

pandas-stubs/_libs/lib.pyi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
from enum import Enum
2+
13
no_default = None
24

5+
class NoDefault(Enum):
6+
no_default: int
7+
38
def infer_dtype(value: object, skipna: bool = ...) -> str: ...

pandas-stubs/_typing.pyi

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ from typing import (
1414
AnyStr,
1515
Callable,
1616
Hashable,
17+
Iterator,
1718
Literal,
1819
Mapping,
1920
Optional,
@@ -65,6 +66,12 @@ class BaseBuffer(Protocol): ...
6566
class ReadBuffer(BaseBuffer, Protocol[AnyStr_cov]): ...
6667
class WriteBuffer(BaseBuffer, Protocol[AnyStr_cov]): ...
6768

69+
class ReadCsvBuffer(ReadBuffer[AnyStr_cov], Protocol[AnyStr_cov]):
70+
def __iter__(self) -> Iterator[AnyStr_cov]: ...
71+
def readline(self) -> AnyStr_cov: ...
72+
@property
73+
def closed(self) -> bool: ...
74+
6875
FilePath = Union[str, PathLike[str]]
6976

7077
Buffer = Union[IO[AnyStr], RawIOBase, BufferedIOBase, TextIOBase, TextIOWrapper, mmap]

pandas-stubs/core/frame.pyi

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1862,55 +1862,6 @@ class DataFrame(NDFrame, OpsMixin):
18621862
self, excel: _bool = ..., sep: _str | None = ..., **kwargs
18631863
) -> None: ...
18641864
@overload
1865-
def to_csv(
1866-
self,
1867-
path_or_buf: FilePathOrBuffer | None,
1868-
sep: _str = ...,
1869-
na_rep: _str = ...,
1870-
float_format: _str | None = ...,
1871-
columns: Sequence[Hashable] | None = ...,
1872-
header: _bool | list[_str] = ...,
1873-
index: _bool = ...,
1874-
index_label: _bool | _str | Sequence[Hashable] | None = ...,
1875-
mode: _str = ...,
1876-
encoding: _str | None = ...,
1877-
compression: _str | Mapping[_str, _str] = ...,
1878-
quoting: int | None = ...,
1879-
quotechar: _str = ...,
1880-
line_terminator: _str | None = ...,
1881-
chunksize: int | None = ...,
1882-
date_format: _str | None = ...,
1883-
doublequote: _bool = ...,
1884-
escapechar: _str | None = ...,
1885-
decimal: _str = ...,
1886-
errors: _str = ...,
1887-
storage_options: dict[_str, Any] | None = ...,
1888-
) -> None: ...
1889-
@overload
1890-
def to_csv(
1891-
self,
1892-
sep: _str = ...,
1893-
na_rep: _str = ...,
1894-
float_format: _str | None = ...,
1895-
columns: Sequence[Hashable] | None = ...,
1896-
header: _bool | list[_str] = ...,
1897-
index: _bool = ...,
1898-
index_label: _bool | _str | Sequence[Hashable] | None = ...,
1899-
mode: _str = ...,
1900-
encoding: _str | None = ...,
1901-
compression: _str | Mapping[_str, _str] = ...,
1902-
quoting: int | None = ...,
1903-
quotechar: _str = ...,
1904-
line_terminator: _str | None = ...,
1905-
chunksize: int | None = ...,
1906-
date_format: _str | None = ...,
1907-
doublequote: _bool = ...,
1908-
escapechar: _str | None = ...,
1909-
decimal: _str = ...,
1910-
errors: _str = ...,
1911-
storage_options: dict[_str, Any] | None = ...,
1912-
) -> _str: ...
1913-
@overload
19141865
def to_json(
19151866
self,
19161867
path_or_buf: FilePathOrBuffer | None,

pandas-stubs/core/generic.pyi

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ from pandas._typing import (
3333
Scalar,
3434
SeriesAxisType,
3535
SortKind,
36+
StorageOptions,
3637
T,
3738
)
3839

@@ -204,17 +205,19 @@ class NDFrame(PandasObject, indexing.IndexingMixin):
204205
@overload
205206
def to_csv(
206207
self,
207-
path_or_buf: FilePathOrBuffer | None,
208+
path_or_buf: FilePathOrBuffer,
208209
sep: _str = ...,
209210
na_rep: _str = ...,
210-
float_format: _str | None = ...,
211-
columns: Sequence[Hashable] | None = ...,
211+
float_format: _str | Callable | None = ...,
212+
columns: list[HashableT] | None = ...,
212213
header: _bool | list[_str] = ...,
213214
index: _bool = ...,
214-
index_label: _bool | _str | Sequence[Hashable] | None = ...,
215-
mode: _str = ...,
215+
index_label: Literal[False] | _str | list[HashableT] | None = ...,
216+
mode: Literal[
217+
"a", "w", "x", "at", "wt", "xt", "ab", "wb", "xb", "w+", "w+b", "a+", "a+b"
218+
] = ...,
216219
encoding: _str | None = ...,
217-
compression: _str | Mapping[_str, _str] = ...,
220+
compression: CompressionOptions = ...,
218221
quoting: int | None = ...,
219222
quotechar: _str = ...,
220223
line_terminator: _str | None = ...,
@@ -224,21 +227,24 @@ class NDFrame(PandasObject, indexing.IndexingMixin):
224227
escapechar: _str | None = ...,
225228
decimal: _str = ...,
226229
errors: _str = ...,
227-
storage_options: dict[_str, Any] | None = ...,
230+
storage_options: StorageOptions = ...,
228231
) -> None: ...
229232
@overload
230233
def to_csv(
231234
self,
235+
path_or_buf: None = ...,
232236
sep: _str = ...,
233237
na_rep: _str = ...,
234-
float_format: _str | None = ...,
235-
columns: Sequence[Hashable] | None = ...,
238+
float_format: _str | Callable | None = ...,
239+
columns: list[HashableT] | None = ...,
236240
header: _bool | list[_str] = ...,
237241
index: _bool = ...,
238-
index_label: _bool | _str | Sequence[Hashable] | None = ...,
239-
mode: _str = ...,
242+
index_label: Literal[False] | _str | list[HashableT] | None = ...,
243+
mode: Literal[
244+
"a", "w", "x", "at", "wt", "xt", "ab", "wb", "xb", "w+", "w+b", "a+", "a+b"
245+
] = ...,
240246
encoding: _str | None = ...,
241-
compression: _str | Mapping[_str, _str] = ...,
247+
compression: CompressionOptions = ...,
242248
quoting: int | None = ...,
243249
quotechar: _str = ...,
244250
line_terminator: _str | None = ...,
@@ -248,7 +254,7 @@ class NDFrame(PandasObject, indexing.IndexingMixin):
248254
escapechar: _str | None = ...,
249255
decimal: _str = ...,
250256
errors: _str = ...,
251-
storage_options: dict[_str, Any] | None = ...,
257+
storage_options: StorageOptions = ...,
252258
) -> _str: ...
253259
def take(
254260
self, indices, axis=..., is_copy: _bool | None = ..., **kwargs

0 commit comments

Comments
 (0)