Flexible and powerful data analysis / manipulation library for Python, providing labeled data structures similar to R data.frame objects, statistical functions, and much more
[X] I have checked that this issue has not already been reported.
[X] I have confirmed this bug exists on the latest version of pandas.
[ ] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
>>> pd.read_csv(io.StringIO("a,b\n1,2\n1,2,3"), engine="python", on_bad_lines=lambda x: print(f"Error: {x}"))
Error: ['1', '2', '3']
a b
0 1 2
>>> pd.read_csv(io.StringIO("a,b\n1,2\n1,2,3"), engine="python", on_bad_lines=lambda x: print(f"Error: {x}"), index_col=False)
<stdin>:1: ParserWarning: Length of header or names does not match length of data. This leads to a loss of data with index_col=False.
a b
0 1 2
1 1 2
Issue Description
If index_col=False is specified when reading a csv, then the on_bad_lines parameter is ignored.
Expected Behavior
on_bad_lines parameter should be respected even when index_col=False is set
Pandas version checks
[X] I have checked that this issue has not already been reported.
[X] I have confirmed this bug exists on the latest version of pandas.
[ ] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
If
index_col=False
is specified when reading a csv, then theon_bad_lines
parameter is ignored.Expected Behavior
on_bad_lines
parameter should be respected even whenindex_col=False
is setInstalled Versions