Skip to content

Commit

Permalink
CSV starting point offset meaningless when no data (#4269)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yves Darmaillac committed Aug 5, 2022
1 parent cdc8554 commit 5ef37dd
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions polars/polars-io/src/csv/read_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ impl<'a> CoreReader<'a> {
&self,
mut bytes: &'b [u8],
eol_char: u8,
) -> Result<(&'b [u8], usize)> {
) -> Result<(&'b [u8], Option<usize>)> {
let starting_point_offset = bytes.as_ptr() as usize;

// Skip all leading white space and the occasional utf8-bom
Expand Down Expand Up @@ -337,7 +337,11 @@ impl<'a> CoreReader<'a> {
}
}

let starting_point_offset = bytes.as_ptr() as usize - starting_point_offset;
let starting_point_offset = if bytes.is_empty() {
None
} else {
Some(bytes.as_ptr() as usize - starting_point_offset)
};

Ok((bytes, starting_point_offset))
}
Expand Down Expand Up @@ -523,7 +527,7 @@ impl<'a> CoreReader<'a> {
let local_bytes = &bytes[read..stop_at_nbytes];

last_read = read;
let offset = read + starting_point_offset;
let offset = read + starting_point_offset.unwrap();
read += parse_lines(
local_bytes,
offset,
Expand Down Expand Up @@ -642,7 +646,7 @@ impl<'a> CoreReader<'a> {
let local_bytes = &bytes[read..stop_at_nbytes];

last_read = read;
let offset = read + starting_point_offset;
let offset = read + starting_point_offset.unwrap();
read += parse_lines(
local_bytes,
offset,
Expand Down

0 comments on commit 5ef37dd

Please sign in to comment.