Skip to content

Commit

Permalink
csv: don't panic if last line misses fields and has no \n
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Jan 15, 2022
1 parent 9691f95 commit 05c03fd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions polars/polars-io/src/csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1432,4 +1432,15 @@ a,b,c,d,1"#;

Ok(())
}

#[test]
fn test_last_line_incomplete() -> Result<()> {
// test a last line that is incomplete and not finishes with a new line char
let csv = "b5bbf310dffe3372fd5d37a18339fea5,6a2752ffad059badb5f1f3c7b9e4905d,-2,0.033191,811.619 0.487341,16,GGTGTGAAATTTCACACC,TTTAATTATAATTAAG,+
b5bbf310dffe3372fd5d37a18339fea5,e3fd7b95be3453a34361da84f815687d,-2,0.0335936,821.465 0.490834,1";
let file = Cursor::new(csv);
let df = CsvReader::new(file).has_header(false).finish()?;
assert_eq!(df.shape(), (2, 9));
Ok(())
}
}
2 changes: 1 addition & 1 deletion polars/polars-io/src/csv_core/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ pub(crate) fn parse_lines(
match iter.next() {
// end of line
None => {
bytes = &bytes[read_sol..];
bytes = &bytes[std::cmp::min(read_sol, bytes.len())..];
break;
}
Some((mut field, needs_escaping)) => {
Expand Down

0 comments on commit 05c03fd

Please sign in to comment.