Skip to content

Commit 2a15f44

Browse files
committed
Deal with DSV files missing columns in certain rows
1 parent bcf9b27 commit 2a15f44

File tree

5 files changed

+19
-0
lines changed

5 files changed

+19
-0
lines changed

nemo/src/io/formats/dsv/reader.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ impl<T: BufRead> DsvReader<T> {
7676
.has_headers(self.ignore_headers)
7777
.double_quote(true)
7878
.quoting(self.quoting)
79+
.flexible(true)
7980
.from_reader(self.read)
8081
}
8182

@@ -107,6 +108,11 @@ impl<T: BufRead> DsvReader<T> {
107108
let mut line_count: u64 = 0;
108109
let mut drop_count: u64 = 0;
109110
for row in dsv_reader.records().flatten() {
111+
if row.len() != expected_file_arity {
112+
drop_count += 1;
113+
continue;
114+
}
115+
110116
for (idx, value) in row.iter().enumerate() {
111117
if idx >= expected_file_arity || skip[idx] {
112118
continue;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@import noHeader :- csv{ resource="sources/missing-columns.csv", ignore_headers=true } .
2+
@import header :- csv{ resource="sources/missing-columns.csv", ignore_headers=false } .
3+
4+
withHeader(?x, ?y) :- header(?x, ?y) .
5+
withoutHeader(?x, ?y) :- noHeader(?x, ?y) .
6+
7+
@export withHeader :- csv{} .
8+
@export withoutHeader :- csv{} .
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
23,42
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
23,42
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
column
2+
23, 42
3+
1337

0 commit comments

Comments
 (0)