Skip to content

Commit 75f5761

Browse files
committed
add test
1 parent ec79ab7 commit 75f5761

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

pandas/tests/frame/methods/test_to_csv.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,3 +1450,22 @@ def test_to_csv_warn_when_zip_tar_and_append_mode(self, tmp_path):
14501450
RuntimeWarning, match=msg, raise_on_extra_warnings=False
14511451
):
14521452
df.to_csv(tar_path, mode="a")
1453+
1454+
def test_to_csv_escape_quotechar(self):
1455+
# GH61514
1456+
df = DataFrame(
1457+
{
1458+
"col_a": ["a", "a2"],
1459+
"col_b": ['b"c', None],
1460+
"col_c": ['de,f"', '"c'],
1461+
}
1462+
)
1463+
1464+
result = df.to_csv(quotechar='"', escapechar="\\", quoting=csv.QUOTE_NONE)
1465+
expected_rows = [
1466+
",col_a,col_b,col_c",
1467+
'0,a,b\\"c,de\\,f\\"',
1468+
'1,a2,,\\"c',
1469+
]
1470+
expected = tm.convert_rows_list_to_csv_str(expected_rows)
1471+
assert result == expected

0 commit comments

Comments
 (0)