@@ -341,7 +341,9 @@ def readline(self):
341341 parser .read_csv (NoNextBuffer ("a\n 1" ))
342342
343343
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+ )
345347def test_on_bad_lines_callable (python_parser_only , bad_line_func ):
346348 # GH 5686
347349 parser = python_parser_only
@@ -367,7 +369,9 @@ def test_on_bad_lines_callable_write_to_external_list(python_parser_only):
367369 bad_sio = StringIO (data )
368370 lst = []
369371
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 ]:
371375 lst .append (bad_line )
372376 return ["2" , "3" ]
373377
@@ -377,7 +381,9 @@ def bad_line_func(bad_line: list[str]) -> list[str]:
377381 assert lst == [["2" , "3" , "4" , "5" , "6" ]]
378382
379383
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+ )
381387@pytest .mark .parametrize ("sep" , ["," , "111" ])
382388def test_on_bad_lines_callable_iterator_true (python_parser_only , bad_line_func , sep ):
383389 # GH 5686
@@ -414,7 +420,7 @@ def test_on_bad_lines_callable_dont_swallow_errors(python_parser_only):
414420 bad_sio = StringIO (data )
415421 msg = "This function is buggy."
416422
417- def bad_line_func (bad_line ):
423+ def bad_line_func (expected_columns , actual_columns , row , bad_line ):
418424 raise ValueError (msg )
419425
420426 with pytest .raises (ValueError , match = msg ):
@@ -432,7 +438,10 @@ def test_on_bad_lines_callable_not_expected_length(python_parser_only):
432438 bad_sio = StringIO (data )
433439
434440 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 ,
436445 )
437446 expected = DataFrame ({"a" : [1 , 2 , 3 ], "b" : [2 , 3 , 4 ]})
438447 tm .assert_frame_equal (result , expected )
@@ -448,7 +457,7 @@ def test_on_bad_lines_callable_returns_none(python_parser_only):
448457"""
449458 bad_sio = StringIO (data )
450459
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 )
452461 expected = DataFrame ({"a" : [1 , 3 ], "b" : [2 , 4 ]})
453462 tm .assert_frame_equal (result , expected )
454463
0 commit comments