Skip to content

Commit a9800c8

Browse files
committed
ENH: Improve io/pickle
Make pickle consistent with upstream pandas Only include what is in the API
1 parent 32db176 commit a9800c8

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

pandas-stubs/_typing.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ class BaseBuffer(Protocol): ...
6767
class ReadBuffer(BaseBuffer, Protocol[AnyStr_cov]): ...
6868
class WriteBuffer(BaseBuffer, Protocol[AnyStr_cov]): ...
6969

70+
class ReadPickleBuffer(ReadBuffer[bytes], Protocol):
71+
def readline(self) -> AnyStr_cov: ...
72+
7073
FilePath = Union[str, PathLike[str]]
7174

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

pandas-stubs/io/pickle.pyi

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
from __future__ import annotations
22

3-
from typing import Literal
3+
from typing import Any
44

5-
from pandas._typing import FilePathOrBuffer
5+
from pandas._typing import (
6+
CompressionOptions,
7+
FilePath,
8+
ReadPickleBuffer,
9+
StorageOptions,
10+
WriteBuffer,
11+
)
612

713
def to_pickle(
8-
obj,
9-
filepath_or_buffer: FilePathOrBuffer,
10-
compression: str | None = ...,
14+
obj: Any,
15+
filepath_or_buffer: FilePath | WriteBuffer[bytes],
16+
compression: CompressionOptions = ...,
1117
protocol: int = ...,
12-
): ...
18+
storage_options: StorageOptions = ...,
19+
) -> None: ...
1320
def read_pickle(
14-
filepath_or_buffer_or_reader: FilePathOrBuffer,
15-
compression: str | Literal["infer", "gzip", "bz2", "zip", "xz"] | None = ...,
16-
): ...
21+
filepath_or_buffer: FilePath | ReadPickleBuffer,
22+
compression: CompressionOptions = ...,
23+
storage_options: StorageOptions = ...,
24+
) -> Any: ...

0 commit comments

Comments
 (0)