Skip to content

Commit a2761f5

Browse files
authored
TST: honor encoding in read_fwf for memory-mapped files (#36737)
1 parent b89e8c0 commit a2761f5

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

pandas/tests/io/parser/test_read_fwf.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,3 +634,24 @@ def test_binary_mode():
634634
df = pd.read_fwf(file)
635635
file.seek(0)
636636
tm.assert_frame_equal(df, df_reference)
637+
638+
639+
@pytest.mark.parametrize("memory_map", [True, False])
640+
def test_encoding_mmap(memory_map):
641+
"""
642+
encoding should be working, even when using a memory-mapped file.
643+
644+
GH 23254.
645+
"""
646+
encoding = "iso8859_1"
647+
data = BytesIO(" 1 A Ä 2\n".encode(encoding))
648+
df = pd.read_fwf(
649+
data,
650+
header=None,
651+
widths=[2, 2, 2, 2],
652+
encoding=encoding,
653+
memory_map=memory_map,
654+
)
655+
data.seek(0)
656+
df_reference = pd.DataFrame([[1, "A", "Ä", 2]])
657+
tm.assert_frame_equal(df, df_reference)

0 commit comments

Comments
 (0)