Skip to content

Commit 6b0e2ca

Browse files
committed
TST: condense test_read_utf_aliases test
-use BytesIO instead of reading & writing file -shorten expected DataFrame
1 parent 1fc6b90 commit 6b0e2ca

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

pandas/io/tests/parser/common.py

+9-15
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import csv
44
import os
55
import platform
6+
from io import BytesIO
67

78
import re
89
import sys
@@ -1474,18 +1475,11 @@ def test_memory_map(self):
14741475

14751476
def test_read_csv_utf_aliases(self):
14761477
# see gh issue 13549
1477-
path = 'test.csv'
1478-
expected = DataFrame({'A': [0, 1], 'B': [2, 3],
1479-
'multibyte_test': ['testing123', 'bananabis'],
1480-
'mb_nums': [154.868, 457.8798]})
1481-
with tm.ensure_clean(path) as path:
1482-
for byte in [8, 16]:
1483-
expected.to_csv(path, encoding='utf-' + str(byte), index=False)
1484-
for fmt in ['utf-{0}', 'utf_{0}', 'UTF-{0}', 'UTF_{0}']:
1485-
encoding = fmt.format(byte)
1486-
for engine in ['c', 'python', None]:
1487-
result = self.read_csv(
1488-
path,
1489-
engine=engine,
1490-
encoding=encoding)
1491-
tm.assert_frame_equal(result, expected)
1478+
expected = pd.DataFrame({'mb_num': [4.8], 'multibyte': ['test']})
1479+
for byte in [8, 16]:
1480+
expected.to_csv(path, encoding='utf-' + str(byte), index=False)
1481+
for fmt in ['utf-{0}', 'utf_{0}', 'UTF-{0}', 'UTF_{0}']:
1482+
encoding = fmt.format(byte)
1483+
data = 'mb_num,multibyte\n4.8,test'.encode(encoding)
1484+
result = self.read_csv(BytesIO(data), encoding=encoding)
1485+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)