Skip to content

Commit b833abd

Browse files
committed
add encoding fixture
1 parent a4de620 commit b833abd

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

pandas/tests/frame/test_to_csv.py

+19-11
Original file line numberDiff line numberDiff line change
@@ -919,29 +919,37 @@ def test_to_csv_path_is_none(self):
919919
recons = pd.read_csv(StringIO(csv_str), index_col=0)
920920
assert_frame_equal(self.frame, recons)
921921

922-
def test_to_csv_compression(self, compression):
923-
924-
df = DataFrame([[0.123456, 0.234567, 0.567567],
925-
[12.32112, 123123.2, 321321.2]],
926-
index=['A', 'B'], columns=['X', 'Y', 'Z'])
922+
@pytest.mark.parametrize('frame, encoding', [
923+
(DataFrame([[0.123456, 0.234567, 0.567567],
924+
[12.32112, 123123.2, 321321.2]],
925+
index=['A', 'B'], columns=['X', 'Y', 'Z']), 'utf-8'),
926+
(DataFrame([['abc', 'def', 'ghi']], columns=['X', 'Y', 'Z']), 'ascii'),
927+
(DataFrame(5 * [[123, u"你好", u"世界"]],
928+
columns=['X', 'Y', 'Z']), 'gb2312'),
929+
(DataFrame(5 * [[123, u"Γειά σου", u"Κόσμε"]],
930+
columns=['X', 'Y', 'Z']), 'cp737')
931+
])
932+
def test_to_csv_compression(self, frame, encoding, compression):
927933

928934
with ensure_clean() as filename:
929935

930-
df.to_csv(filename, compression=compression)
936+
frame.to_csv(filename, compression=compression, encoding=encoding)
931937

932938
# test the round trip - to_csv -> read_csv
933939
rs = read_csv(filename, compression=compression,
934-
index_col=0)
935-
assert_frame_equal(df, rs)
940+
index_col=0, encoding=encoding)
941+
assert_frame_equal(frame, rs)
936942

937943
# explicitly make sure file is compressed
938944
with tm.decompress_file(filename, compression) as fh:
939-
text = fh.read().decode('utf8')
940-
for col in df.columns:
945+
text = fh.read().decode(encoding)
946+
for col in frame.columns:
941947
assert col in text
942948

943949
with tm.decompress_file(filename, compression) as fh:
944-
assert_frame_equal(df, read_csv(fh, index_col=0))
950+
assert_frame_equal(frame, read_csv(fh,
951+
index_col=0,
952+
encoding=encoding))
945953

946954
def test_to_csv_date_format(self):
947955
with ensure_clean('__tmp_to_csv_date_format__') as path:

0 commit comments

Comments
 (0)