Skip to content

Commit

Permalink
csv don't skip delimiter in whitespace trimming (#3796)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Jun 24, 2022
1 parent 68021f1 commit b59b6d7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion polars/polars-io/src/csv_core/csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ impl<'a> CoreReader<'a> {
let starting_point_offset = bytes.as_ptr() as usize;

// Skip all leading white space and the occasional utf8-bom
bytes = skip_whitespace(skip_bom(bytes));
bytes = skip_whitespace_exclude(skip_bom(bytes), self.delimiter);
// \n\n can be a empty string row of a single column
// in other cases we skip it.
if self.schema.len() > 1 {
Expand Down
12 changes: 12 additions & 0 deletions py-polars/tests/io/test_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,3 +437,15 @@ def test_glob_csv(io_test_dir: str) -> None:
path = os.path.join(io_test_dir, "small*.csv")
assert pl.scan_csv(path).collect().shape == (3, 11)
assert pl.read_csv(path).shape == (3, 11)


def test_csv_whitepsace_do_not_skip() -> None:
csv = "\t\t\t\t0\t1"
assert pl.read_csv(csv.encode(), sep="\t", has_header=False).to_dict(False) == {
"column_1": [None],
"column_2": [None],
"column_3": [None],
"column_4": [None],
"column_5": [0],
"column_6": [1],
}

0 comments on commit b59b6d7

Please sign in to comment.