Skip to content

Commit 0d87bd1

Browse files
authored
TST: read binary file objects with read_fwf (#36735)
1 parent 84acb08 commit 0d87bd1

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

pandas/tests/io/parser/test_read_fwf.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from datetime import datetime
88
from io import BytesIO, StringIO
9+
from pathlib import Path
910

1011
import numpy as np
1112
import pytest
@@ -614,3 +615,22 @@ def test_fwf_compression(compression_only, infer):
614615

615616
result = read_fwf(path, **kwargs)
616617
tm.assert_frame_equal(result, expected)
618+
619+
620+
def test_binary_mode():
621+
"""
622+
read_fwf supports opening files in binary mode.
623+
624+
GH 18035.
625+
"""
626+
data = """aas aas aas
627+
bba bab b a"""
628+
df_reference = pd.DataFrame(
629+
[["bba", "bab", "b a"]], columns=["aas", "aas.1", "aas.2"], index=[0]
630+
)
631+
with tm.ensure_clean() as path:
632+
Path(path).write_text(data)
633+
with open(path, "rb") as file:
634+
df = pd.read_fwf(file)
635+
file.seek(0)
636+
tm.assert_frame_equal(df, df_reference)

0 commit comments

Comments
 (0)