Skip to content

ENH: Improve to_csv and from_{fwf,csv,table} #248

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 10 commits into from
Sep 5, 2022
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
8 changes: 8 additions & 0 deletions pandas-stubs/_typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ from typing import (
AnyStr,
Callable,
Hashable,
Iterator,
Literal,
Mapping,
Optional,
Expand Down Expand Up @@ -66,6 +67,12 @@ class BaseBuffer(Protocol): ...
class ReadBuffer(BaseBuffer, Protocol[AnyStr_cov]): ...
class WriteBuffer(BaseBuffer, Protocol[AnyStr_cov]): ...

class ReadCsvBuffer(ReadBuffer[AnyStr_cov], Protocol[AnyStr_cov]):
def __iter__(self) -> Iterator[AnyStr_cov]: ...
def readline(self) -> AnyStr_cov: ...
@property
def closed(self) -> bool: ...

class WriteExcelBuffer(WriteBuffer[bytes], Protocol):
def truncate(self, size: Union[int, None] = ...) -> int: ...

Expand Down Expand Up @@ -242,6 +249,7 @@ JsonSeriesOrient = Literal["split", "records", "index"]
TimestampConvention = Literal["start", "end", "s", "e"]

CSVEngine = Literal["c", "python", "pyarrow", "python-fwf"]
CSVQuoting = Literal[0, 1, 2, 3]

HDFCompLib = Literal["zlib", "lzo", "bzip2", "blosc"]
ParquetEngine = Literal["auto", "pyarrow", "fastparquet"]
Expand Down
49 changes: 0 additions & 49 deletions pandas-stubs/core/frame.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1917,55 +1917,6 @@ class DataFrame(NDFrame, OpsMixin):
self, excel: _bool = ..., sep: _str | None = ..., **kwargs
) -> None: ...
@overload
def to_csv(
self,
path_or_buf: FilePathOrBuffer | None,
sep: _str = ...,
na_rep: _str = ...,
float_format: _str | None = ...,
columns: Sequence[Hashable] | None = ...,
header: _bool | list[_str] = ...,
index: _bool = ...,
index_label: _bool | _str | Sequence[Hashable] | None = ...,
mode: _str = ...,
encoding: _str | None = ...,
compression: _str | Mapping[_str, _str] = ...,
quoting: Literal[0, 1, 2, 3] | None = ...,
quotechar: _str = ...,
line_terminator: _str | None = ...,
chunksize: int | None = ...,
date_format: _str | None = ...,
doublequote: _bool = ...,
escapechar: _str | None = ...,
decimal: _str = ...,
errors: _str = ...,
storage_options: dict[_str, Any] | None = ...,
) -> None: ...
@overload
def to_csv(
self,
sep: _str = ...,
na_rep: _str = ...,
float_format: _str | None = ...,
columns: Sequence[Hashable] | None = ...,
header: _bool | list[_str] = ...,
index: _bool = ...,
index_label: _bool | _str | Sequence[Hashable] | None = ...,
mode: _str = ...,
encoding: _str | None = ...,
compression: _str | Mapping[_str, _str] = ...,
quoting: Literal[0, 1, 2, 3] | None = ...,
quotechar: _str = ...,
line_terminator: _str | None = ...,
chunksize: int | None = ...,
date_format: _str | None = ...,
doublequote: _bool = ...,
escapechar: _str | None = ...,
decimal: _str = ...,
errors: _str = ...,
storage_options: dict[_str, Any] | None = ...,
) -> _str: ...
@overload
def to_json(
self,
path_or_buf: FilePathOrBuffer | None,
Expand Down
32 changes: 17 additions & 15 deletions pandas-stubs/core/generic.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ from pandas._typing import (
ArrayLike,
Axis,
CompressionOptions,
CSVQuoting,
Dtype,
DtypeArg,
FilePath,
Expand Down Expand Up @@ -231,18 +232,18 @@ class NDFrame(PandasObject, indexing.IndexingMixin):
@overload
def to_csv(
self,
path_or_buf: FilePathOrBuffer | None,
path_or_buf: FilePathOrBuffer,
sep: _str = ...,
na_rep: _str = ...,
float_format: _str | None = ...,
columns: Sequence[Hashable] | None = ...,
float_format: _str | Callable[[object], _str] | None = ...,
columns: list[HashableT] | None = ...,
header: _bool | list[_str] = ...,
index: _bool = ...,
index_label: _bool | _str | Sequence[Hashable] | None = ...,
mode: _str = ...,
index_label: Literal[False] | _str | list[HashableT] | None = ...,
mode: FileWriteMode = ...,
encoding: _str | None = ...,
compression: _str | Mapping[_str, _str] = ...,
quoting: Literal[0, 1, 2, 3] | None = ...,
compression: CompressionOptions = ...,
quoting: CSVQuoting = ...,
quotechar: _str = ...,
line_terminator: _str | None = ...,
chunksize: int | None = ...,
Expand All @@ -251,22 +252,23 @@ class NDFrame(PandasObject, indexing.IndexingMixin):
escapechar: _str | None = ...,
decimal: _str = ...,
errors: _str = ...,
storage_options: dict[_str, Any] | None = ...,
storage_options: StorageOptions = ...,
) -> None: ...
@overload
def to_csv(
self,
path_or_buf: None = ...,
sep: _str = ...,
na_rep: _str = ...,
float_format: _str | None = ...,
columns: Sequence[Hashable] | None = ...,
float_format: _str | Callable[[object], _str] | None = ...,
columns: list[HashableT] | None = ...,
header: _bool | list[_str] = ...,
index: _bool = ...,
index_label: _bool | _str | Sequence[Hashable] | None = ...,
mode: _str = ...,
index_label: Literal[False] | _str | list[HashableT] | None = ...,
mode: FileWriteMode = ...,
encoding: _str | None = ...,
compression: _str | Mapping[_str, _str] = ...,
quoting: Literal[0, 1, 2, 3] | None = ...,
compression: CompressionOptions = ...,
quoting: CSVQuoting = ...,
quotechar: _str = ...,
line_terminator: _str | None = ...,
chunksize: int | None = ...,
Expand All @@ -275,7 +277,7 @@ class NDFrame(PandasObject, indexing.IndexingMixin):
escapechar: _str | None = ...,
decimal: _str = ...,
errors: _str = ...,
storage_options: dict[_str, Any] | None = ...,
storage_options: StorageOptions = ...,
) -> _str: ...
def take(
self, indices, axis=..., is_copy: _bool | None = ..., **kwargs
Expand Down
7 changes: 4 additions & 3 deletions pandas-stubs/io/clipboards.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ from pandas.core.series import Series
from pandas._typing import (
CompressionOptions,
CSVEngine,
CSVQuoting,
DtypeArg,
StorageOptions,
npt,
Expand Down Expand Up @@ -71,7 +72,7 @@ def read_clipboard(
decimal: str = ...,
lineterminator: str | None = ...,
quotechar: str = ...,
quoting: Literal[0, 1, 2, 3] | None = ...,
quoting: CSVQuoting = ...,
doublequote: bool = ...,
escapechar: str | None = ...,
comment: str | None = ...,
Expand Down Expand Up @@ -137,7 +138,7 @@ def read_clipboard(
decimal: str = ...,
lineterminator: str | None = ...,
quotechar: str = ...,
quoting: Literal[0, 1, 2, 3] | None = ...,
quoting: CSVQuoting = ...,
doublequote: bool = ...,
escapechar: str | None = ...,
comment: str | None = ...,
Expand Down Expand Up @@ -203,7 +204,7 @@ def read_clipboard(
decimal: str = ...,
lineterminator: str | None = ...,
quotechar: str = ...,
quoting: Literal[0, 1, 2, 3] | None = ...,
quoting: CSVQuoting = ...,
doublequote: bool = ...,
escapechar: str | None = ...,
comment: str | None = ...,
Expand Down
34 changes: 17 additions & 17 deletions pandas-stubs/io/common.pyi
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
from typing import (
IO,
AnyStr,
Generic,
)
from pandas._typing import CompressionDict
class IOHandles(Generic[AnyStr]):
handle: IO[AnyStr]
compression: CompressionDict
created_handles: list[IO[AnyStr]]
is_wrapped: bool
def close(self) -> None: ...
def __enter__(self) -> IOHandles[AnyStr]: ...
def __exit__(self, *args: object) -> None: ...
def __init__(self, handle, compression, created_handles, is_wrapped) -> None: ...
from typing import (
IO,
AnyStr,
Generic,
)

from pandas._typing import CompressionDict

class IOHandles(Generic[AnyStr]):
handle: IO[AnyStr]
compression: CompressionDict
created_handles: list[IO[AnyStr]]
is_wrapped: bool
def close(self) -> None: ...
def __enter__(self) -> IOHandles[AnyStr]: ...
def __exit__(self, *args: object) -> None: ...
def __init__(self, handle, compression, created_handles, is_wrapped) -> None: ...
Loading