Skip to content

Commit a3ea443

Browse files
committed
BUG: Add exception when different number of fields present in file lines
Addresses issue in pandas-dev#12519 by raising exception when 'filepath_or_buffer' in 'read_csv' contains different number of fields in input lines.
1 parent c69037c commit a3ea443

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

pandas/src/parser/tokenizer.c

+7-3
Original file line numberDiff line numberDiff line change
@@ -537,9 +537,13 @@ static int end_line(parser_t *self) {
537537
}
538538

539539
while (fields < ex_fields){
540-
end_field(self);
541-
/* printf("Prior word: %s\n", self->words[self->words_len - 2]); */
542-
fields++;
540+
self->error_msg = (char*) malloc(100);
541+
sprintf(self->error_msg, "Expected %d fields in line %d, saw %d\n",
542+
ex_fields, self->file_lines, fields);
543+
544+
TRACE(("Error at line %d, %d fields\n", self->file_lines, fields));
545+
546+
return -1;
543547
}
544548
}
545549

0 commit comments

Comments
 (0)