@@ -341,7 +341,9 @@ def readline(self):
341
341
parser .read_csv (NoNextBuffer ("a\n 1" ))
342
342
343
343
344
- @pytest .mark .parametrize ("bad_line_func" , [lambda x : ["2" , "3" ], lambda x : x [:2 ]])
344
+ @pytest .mark .parametrize (
345
+ "bad_line_func" , [lambda x , y , z , a : ["2" , "3" ], lambda x , y , z , a : a [:2 ]]
346
+ )
345
347
def test_on_bad_lines_callable (python_parser_only , bad_line_func ):
346
348
# GH 5686
347
349
parser = python_parser_only
@@ -367,7 +369,9 @@ def test_on_bad_lines_callable_write_to_external_list(python_parser_only):
367
369
bad_sio = StringIO (data )
368
370
lst = []
369
371
370
- def bad_line_func (bad_line : list [str ]) -> list [str ]:
372
+ def bad_line_func (
373
+ expected_columns : int , actual_columns : int , row : int , bad_line : list [str ]
374
+ ) -> list [str ]:
371
375
lst .append (bad_line )
372
376
return ["2" , "3" ]
373
377
@@ -377,7 +381,9 @@ def bad_line_func(bad_line: list[str]) -> list[str]:
377
381
assert lst == [["2" , "3" , "4" , "5" , "6" ]]
378
382
379
383
380
- @pytest .mark .parametrize ("bad_line_func" , [lambda x : ["foo" , "bar" ], lambda x : x [:2 ]])
384
+ @pytest .mark .parametrize (
385
+ "bad_line_func" , [lambda x , y , z , a : ["foo" , "bar" ], lambda x , y , z , a : a [:2 ]]
386
+ )
381
387
@pytest .mark .parametrize ("sep" , ["," , "111" ])
382
388
def test_on_bad_lines_callable_iterator_true (python_parser_only , bad_line_func , sep ):
383
389
# GH 5686
@@ -414,7 +420,7 @@ def test_on_bad_lines_callable_dont_swallow_errors(python_parser_only):
414
420
bad_sio = StringIO (data )
415
421
msg = "This function is buggy."
416
422
417
- def bad_line_func (bad_line ):
423
+ def bad_line_func (expected_columns , actual_columns , row , bad_line ):
418
424
raise ValueError (msg )
419
425
420
426
with pytest .raises (ValueError , match = msg ):
@@ -432,7 +438,10 @@ def test_on_bad_lines_callable_not_expected_length(python_parser_only):
432
438
bad_sio = StringIO (data )
433
439
434
440
result = parser .read_csv_check_warnings (
435
- ParserWarning , "Length of header or names" , bad_sio , on_bad_lines = lambda x : x
441
+ ParserWarning ,
442
+ "Length of header or names" ,
443
+ bad_sio ,
444
+ on_bad_lines = lambda x , y , z , a : a ,
436
445
)
437
446
expected = DataFrame ({"a" : [1 , 2 , 3 ], "b" : [2 , 3 , 4 ]})
438
447
tm .assert_frame_equal (result , expected )
@@ -448,7 +457,7 @@ def test_on_bad_lines_callable_returns_none(python_parser_only):
448
457
"""
449
458
bad_sio = StringIO (data )
450
459
451
- result = parser .read_csv (bad_sio , on_bad_lines = lambda x : None )
460
+ result = parser .read_csv (bad_sio , on_bad_lines = lambda x , y , z , a : None )
452
461
expected = DataFrame ({"a" : [1 , 3 ], "b" : [2 , 4 ]})
453
462
tm .assert_frame_equal (result , expected )
454
463
0 commit comments