Skip to content

ENH: Add BytesIOWrapper #42669

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 6 commits into from
Aug 4, 2021
Merged

ENH: Add BytesIOWrapper #42669

merged 6 commits into from
Aug 4, 2021

Conversation

lithomas1
Copy link
Member

@lithomas1 lithomas1 commented Jul 22, 2021

Precursor for pyarrow csv reader integration.

@jorisvandenbossche Do you know if there is any workaround I can use to read StringIO's on the arrow side? Adding this wrapper feels very hacky.

@lithomas1 lithomas1 requested a review from twoertwein July 26, 2021 15:43
@jreback jreback added Enhancement IO Data IO issues that don't fit into a more specific label Refactor Internal refactoring of code labels Jul 28, 2021
@lithomas1 lithomas1 requested review from jreback and twoertwein July 28, 2021 17:13
@@ -878,6 +888,46 @@ def __next__(self) -> str:
return newline.lstrip("\n")


# Wrapper that wraps a StringIO buffer and reads bytes from it
# Created for compat with pyarrow read_csv
class BytesIOWrapper(io.BytesIO):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what pandas's policy is on public/private classes. Maybe name the class _BytesIOWrapper. @jreback

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is fine, this entire module is de-facto private.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and we already expose TextIOWrapper so this is similar

@lithomas1 lithomas1 added this to the 1.4 milestone Aug 3, 2021
@lithomas1
Copy link
Member Author

gentle ping @jreback @jorisvandenbossche this is blocking integration of the pyarrow csv reader.

@@ -878,6 +888,46 @@ def __next__(self) -> str:
return newline.lstrip("\n")


# Wrapper that wraps a StringIO buffer and reads bytes from it
# Created for compat with pyarrow read_csv
class BytesIOWrapper(io.BytesIO):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is fine, this entire module is de-facto private.

@@ -878,6 +888,46 @@ def __next__(self) -> str:
return newline.lstrip("\n")


# Wrapper that wraps a StringIO buffer and reads bytes from it
# Created for compat with pyarrow read_csv
class BytesIOWrapper(io.BytesIO):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and we already expose TextIOWrapper so this is similar

@jreback jreback merged commit c5e236b into pandas-dev:master Aug 4, 2021
@jreback
Copy link
Contributor

jreback commented Aug 4, 2021

thanks @lithomas1 very nice! and thanks @twoertwein for reviewing

@lithomas1 lithomas1 deleted the bytesiowrapper branch August 9, 2021 17:06
feefladder pushed a commit to feefladder/pandas that referenced this pull request Sep 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement IO Data IO issues that don't fit into a more specific label Refactor Internal refactoring of code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

REF: in pandas.io.common integerate BytesIOWrapper into IOHandle
3 participants