8000 BUG: Help python csv engine read binary buffers by fiendish · Pull Request #27925 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

BUG: Help python csv engine read binary buffers #27925

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
Aug 19, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
remove no_close and compare with non-open read
  • Loading branch information
fiendish committed Aug 16, 2019
commit d6625325c5930d5c4888056a6feb0a64c4037cc9
4 changes: 1 addition & 3 deletions pandas/io/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,6 @@ def _get_handle(
except ImportError:
need_text_wrapping = BufferedIOBase

no_close = BufferedIOBase

handles = list()
f = path_or_buf

Expand Down Expand Up @@ -423,7 +421,7 @@ def _get_handle(
from io import TextIOWrapper

g = TextIOWrapper(f, encoding=encoding, newline="")
if not isinstance(f, no_close):
if not isinstance(f, BufferedIOBase):
handles.append(g)
f = g

Expand Down
10 changes: 6 additions & 4 deletions pandas/tests/io/parser/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2039,13 +2039,15 @@ def test_binary_mode_file_buffers(all_parsers, csv_dir_path, fname, encoding):
parser = all_parsers

fpath = os.path.join(csv_dir_path, fname)
expected = parser.read_csv(fpath, encoding=encoding)

with open(fpath, mode="r", encoding=encoding) as fa:
df_a = parser.read_csv(fa)
with open(fpath, mode="rb") as fb:
df_b = parser.read_csv(fb, encoding=encoding)
result = parser.read_csv(fa)
tm.assert_frame_equal(expected, result)

tm.assert_frame_equal(df_b, df_a)
with open(fpath, mode="rb") as fb:
result = parser.read_csv(fb, encoding=encoding)
tm.assert_frame_equal(expected, result)


def test_invalid_file_buffer_class(all_parsers):
Expand Down
0