From a3ea443b37fb83cc734f4293d26b4e6f7a03641a Mon Sep 17 00:00:00 2001 From: Volodymyr Fomenko Date: Fri, 4 Mar 2016 17:30:20 +0200 Subject: [PATCH] BUG: Add exception when different number of fields present in file lines Addresses issue in #12519 by raising exception when 'filepath_or_buffer' in 'read_csv' contains different number of fields in input lines. --- pandas/src/parser/tokenizer.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pandas/src/parser/tokenizer.c b/pandas/src/parser/tokenizer.c index dae15215929b7..1cf0b32d54f0b 100644 --- a/pandas/src/parser/tokenizer.c +++ b/pandas/src/parser/tokenizer.c @@ -537,9 +537,13 @@ static int end_line(parser_t *self) { } while (fields < ex_fields){ - end_field(self); - /* printf("Prior word: %s\n", self->words[self->words_len - 2]); */ - fields++; + self->error_msg = (char*) malloc(100); + sprintf(self->error_msg, "Expected %d fields in line %d, saw %d\n", + ex_fields, self->file_lines, fields); + + TRACE(("Error at line %d, %d fields\n", self->file_lines, fields)); + + return -1; } }