Skip to content

Commit

Permalink
python fix panic in csv parser with empty quote char
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Oct 30, 2021
1 parent a0be21d commit 9deef27
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
11 changes: 10 additions & 1 deletion py-polars/src/dataframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,16 @@ impl PyDataFrame {
) -> PyResult<Self> {
let null_values = null_values.map(|w| w.0);
let comment_char = comment_char.map(|s| s.as_bytes()[0]);
let quote_char = quote_char.map(|s| s.as_bytes()[0]);

let quote_char = if let Some(s) = quote_char {
if s.is_empty() {
None
} else {
Some(s.as_bytes()[0])
}
} else {
None
};
let encoding = match encoding {
"utf8" => CsvEncoding::Utf8,
"utf8-lossy" => CsvEncoding::LossyUtf8,
Expand Down
5 changes: 5 additions & 0 deletions py-polars/tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,3 +323,8 @@ def test_date_list_fmt():
[2020-01-02]
[2020-01-05, 2020-01-05]
]"""


def test_csv_empty_quotes_char():
# panicked in: https://github.com/pola-rs/polars/issues/1622
pl.read_csv(b"a,b,c,d\nA1,B1,C1,1\nA2,B2,C2,2\n", quote_char="")

0 comments on commit 9deef27

Please sign in to comment.