Skip to content
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

ENH: Remove mode property from BaseBuffer #60660

Open
1 of 3 tasks
ethantkoenig opened this issue Jan 5, 2025 · 0 comments
Open
1 of 3 tasks

ENH: Remove mode property from BaseBuffer #60660

ethantkoenig opened this issue Jan 5, 2025 · 0 comments
Labels
Enhancement Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@ethantkoenig
Copy link

ethantkoenig commented Jan 5, 2025

Feature Type

  • Adding new functionality to pandas

  • Changing existing functionality in pandas

  • Removing existing functionality in pandas

Problem Description

I would like to pass an io.IOBase (or a subclass, such as botocore.response.StreamingBody) to functions that accept one of the various "buffer" classes (ReadBuffer, ReadCsvBuffer, etc.)

Currently, this does not type-check (or, at least not with Pyright), because the BaseBuffer protocol defines a mode property:

pandas/pandas/_typing.py

Lines 271 to 274 in 1be2637

@property
def mode(self) -> str:
# for _get_filepath_or_buffer
...

Type "IOBase" is not assignable to declared type "ReadCsvBuffer[bytes]"
  "IOBase" is incompatible with protocol "ReadCsvBuffer[bytes]"
    "mode" is not present

Feature Description

AFAICT, the only place the BaseBuffer.mode property is accessed is this getattr call, which can handle the property not existing (due to the default value).

pandas/pandas/io/common.py

Lines 1196 to 1198 in 1be2637

return isinstance(handle, _get_binary_io_classes()) or "b" in getattr(
handle, "mode", mode
)

Can we just remove the mode property from BaseBuffer, since (AFAICT) it's not actually required by any Pandas code that handles BaseBuffer instances (and/or instances of BaseBuffer subclasses)?

Alternative Solutions

If python/typing#601 ever becomes a reality, BaseBuffer.mode could be marked as an "optional" property.

Additional Context

No response

@ethantkoenig ethantkoenig added Enhancement Needs Triage Issue that has not been reviewed by a pandas team member labels Jan 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

No branches or pull requests

1 participant