File tree 3 files changed +28
-7
lines changed
3 files changed +28
-7
lines changed Original file line number Diff line number Diff line change @@ -137,12 +137,13 @@ def test_integer_thousands(self):
137
137
tm .assert_almost_equal (result [0 ], expected )
138
138
139
139
def test_skip_bad_lines (self ):
140
+ # too many lines, see #2430 for why
140
141
data = ('a:b:c\n '
141
142
'd:e:f\n '
142
143
'g:h:i\n '
143
- 'j:k\n '
144
+ 'j:k:l:m \n '
144
145
'l:m:n\n '
145
- 'o:p' )
146
+ 'o:p:q:r ' )
146
147
147
148
reader = TextReader (StringIO (data ), delimiter = ':' ,
148
149
header = None )
Original file line number Diff line number Diff line change @@ -720,10 +720,11 @@ def test_read_table_unicode(self):
720
720
self .assert_ (isinstance (df1 ['X0' ].values [0 ], unicode ))
721
721
722
722
def test_read_table_wrong_num_columns (self ):
723
+ # too few!
723
724
data = """A,B,C,D,E,F
724
- 1,2,3,4,5
725
- 6,7,8,9,10
726
- 11,12,13,14,15
725
+ 1,2,3,4,5,6
726
+ 6,7,8,9,10,11,12
727
+ 11,12,13,14,15,16
727
728
"""
728
729
self .assertRaises (Exception , self .read_csv , StringIO (data ))
729
730
@@ -1302,6 +1303,15 @@ def test_nonexistent_path(self):
1302
1303
path = '%s.csv' % tm .rands (10 )
1303
1304
self .assertRaises (Exception , self .read_csv , path )
1304
1305
1306
+ def test_missing_trailing_delimiters (self ):
1307
+ data = """A,B,C,D
1308
+ 1,2,3,4
1309
+ 1,3,3,
1310
+ 1,4,5"""
1311
+ result = self .read_csv (StringIO (data ))
1312
+ self .assertTrue (result ['D' ].isnull ()[1 :].all ())
1313
+
1314
+
1305
1315
class TestPythonParser (ParserTests , unittest .TestCase ):
1306
1316
1307
1317
def read_csv (self , * args , ** kwds ):
@@ -1645,6 +1655,7 @@ def test_utf16_example(self):
1645
1655
result = self .read_table (buf , encoding = 'utf-16' )
1646
1656
self .assertEquals (len (result ), 50 )
1647
1657
1658
+
1648
1659
class TestCParserHighMemory (ParserTests , unittest .TestCase ):
1649
1660
1650
1661
def read_csv (self , * args , ** kwds ):
Original file line number Diff line number Diff line change @@ -447,7 +447,7 @@ static int end_line(parser_t *self) {
447
447
}
448
448
}
449
449
450
- if (!(self -> lines <= self -> header + 1 ) && fields != ex_fields ) {
450
+ if (!(self -> lines <= self -> header + 1 ) && fields > ex_fields ) {
451
451
// increment file line count
452
452
self -> file_lines ++ ;
453
453
@@ -478,7 +478,16 @@ static int end_line(parser_t *self) {
478
478
free (msg );
479
479
}
480
480
}
481
- } else {
481
+ }
482
+ else {
483
+ /* missing trailing delimiters */
484
+ if (self -> lines >= self -> header + 1 && self -> lines > 0 ) {
485
+ while (fields < ex_fields ){
486
+ end_field (self );
487
+ fields ++ ;
488
+ }
489
+ }
490
+
482
491
// increment both line counts
483
492
self -> file_lines ++ ;
484
493
You can’t perform that action at this time.
0 commit comments