From 715158fdcb85a85834a3eac0a538d81531d79be1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Wed, 30 Sep 2020 01:47:05 -0400 Subject: [PATCH] TST: read binary file objects with read_fwf --- pandas/tests/io/parser/test_read_fwf.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pandas/tests/io/parser/test_read_fwf.py b/pandas/tests/io/parser/test_read_fwf.py index 127d0dc4c9829..13519154f82b8 100644 --- a/pandas/tests/io/parser/test_read_fwf.py +++ b/pandas/tests/io/parser/test_read_fwf.py @@ -6,6 +6,7 @@ from datetime import datetime from io import BytesIO, StringIO +from pathlib import Path import numpy as np import pytest @@ -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)