File tree 2 files changed +27
-1
lines changed
2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -2190,7 +2190,17 @@ def _next_line(self):
2190
2190
next (self .data )
2191
2191
2192
2192
while True :
2193
- orig_line = next (self .data )
2193
+ try :
2194
+ orig_line = next (self .data )
2195
+ except csv .Error as e :
2196
+ if 'NULL byte' in str (e ):
2197
+ raise csv .Error (
2198
+ 'NULL byte detected. This byte '
2199
+ 'cannot be processed in Python\' s '
2200
+ 'native csv library at the moment, '
2201
+ 'so please pass in engine=\' c\' instead.' )
2202
+ else :
2203
+ raise
2194
2204
line = self ._check_comments ([orig_line ])[0 ]
2195
2205
self .pos += 1
2196
2206
if (not self .skip_blank_lines and
Original file line number Diff line number Diff line change @@ -1503,3 +1503,19 @@ def test_memory_map(self):
1503
1503
1504
1504
out = self .read_csv (mmap_file , memory_map = True )
1505
1505
tm .assert_frame_equal (out , expected )
1506
+
1507
+ def test_null_byte_char (self ):
1508
+ # see gh-2741
1509
+ data = '\x00 ,foo'
1510
+ cols = ['a' , 'b' ]
1511
+
1512
+ expected = DataFrame ([[np .nan , 'foo' ]],
1513
+ columns = cols )
1514
+
1515
+ if self .engine == 'c' :
1516
+ out = self .read_csv (StringIO (data ), names = cols )
1517
+ tm .assert_frame_equal (out , expected )
1518
+ else :
1519
+ msg = "NULL byte detected"
1520
+ with tm .assertRaisesRegexp (csv .Error , msg ):
1521
+ self .read_csv (StringIO (data ), names = cols )
You can’t perform that action at this time.
0 commit comments