Skip to content

TYP: fix ReadPickleBuffer #48144

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 7 commits into from
Oct 25, 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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ repos:
types: [python]
stages: [manual]
additional_dependencies: &pyright_dependencies
- [email protected].264
- [email protected].276
- id: pyright_reportGeneralTypeIssues
# note: assumes python env is setup and activated
name: pyright reportGeneralTypeIssues
Expand Down
12 changes: 6 additions & 6 deletions pandas/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,6 @@ def mode(self) -> str:
# for _get_filepath_or_buffer
...

def fileno(self) -> int:
# for _MMapWrapper
...

def seek(self, __offset: int, __whence: int = ...) -> int:
# with one argument: gzip.GzipFile, bz2.BZ2File
# with two arguments: zip.ZipFile, read_sas
Expand All @@ -217,7 +213,7 @@ def tell(self) -> int:


class ReadBuffer(BaseBuffer, Protocol[AnyStr_cov]):
def read(self, __n: int | None = ...) -> AnyStr_cov:
def read(self, __n: int = ...) -> AnyStr_cov:
# for BytesIOWrapper, gzip.GzipFile, bz2.BZ2File
...

Expand All @@ -233,7 +229,7 @@ def flush(self) -> Any:


class ReadPickleBuffer(ReadBuffer[bytes], Protocol):
def readline(self) -> AnyStr_cov:
def readline(self) -> bytes:
...


Expand All @@ -247,6 +243,10 @@ def __iter__(self) -> Iterator[AnyStr_cov]:
# for engine=python
...

def fileno(self) -> int:
# for _MMapWrapper
...

def readline(self) -> AnyStr_cov:
# for engine=python
...
Expand Down
4 changes: 4 additions & 0 deletions pandas/io/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
CompressionOptions,
FilePath,
ReadBuffer,
ReadCsvBuffer,
StorageOptions,
WriteBuffer,
)
Expand Down Expand Up @@ -1106,6 +1107,9 @@ def _maybe_memory_map(
if not memory_map:
return handle, memory_map, handles

# mmap used by only read_csv
handle = cast(ReadCsvBuffer, handle)

# need to open the file first
if isinstance(handle, str):
handle = open(handle, "rb")
Expand Down
5 changes: 1 addition & 4 deletions pandas/io/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,10 +712,7 @@ def get_data_from_filepath(
storage_options=storage_options,
) as handle_obj:
filepath_or_buffer = (
# error: Incompatible types in assignment (expression has type
# "Union[str, IO[str]]", variable has type "Union[Union[str,
# PathLike[str]], bytes, ReadBuffer[bytes], ReadBuffer[str]]")
handle_obj.handle.read() # type: ignore[assignment]
handle_obj.handle.read()
if hasattr(handle_obj.handle, "read")
else handle_obj.handle
)
Expand Down