Skip to content

TST: read binary file objects with read_fwf #36735

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 1 commit into from
Sep 30, 2020
Merged
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
20 changes: 20 additions & 0 deletions pandas/tests/io/parser/test_read_fwf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from datetime import datetime
from io import BytesIO, StringIO
from pathlib import Path

import numpy as np
import pytest
Expand Down Expand Up @@ -614,3 +615,22 @@ def test_fwf_compression(compression_only, infer):

result = read_fwf(path, **kwargs)
tm.assert_frame_equal(result, expected)


def test_binary_mode():
"""
read_fwf supports opening files in binary mode.

GH 18035.
"""
data = """aas aas aas
bba bab b a"""
df_reference = pd.DataFrame(
[["bba", "bab", "b a"]], columns=["aas", "aas.1", "aas.2"], index=[0]
)
with tm.ensure_clean() as path:
Path(path).write_text(data)
with open(path, "rb") as file:
df = pd.read_fwf(file)
file.seek(0)
tm.assert_frame_equal(df, df_reference)