Skip to content

BUG: Read_csv won't warn/skip bad lines when nrows is being used #50409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
2 of 3 tasks
d2thebee opened this issue Dec 23, 2022 · 2 comments
Closed
2 of 3 tasks

BUG: Read_csv won't warn/skip bad lines when nrows is being used #50409

d2thebee opened this issue Dec 23, 2022 · 2 comments
Labels
Bug IO CSV read_csv, to_csv Needs Info Clarification about behavior needed to assess issue

Comments

@d2thebee
Copy link

Pandas version checks

  • I have checked that this issue has not already been reported.

  • 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

import pandas as pd
data = pd.read_csv('file.csv', sep='¬', encoding = 'ISO-8859-1', engine='python', on_bad_lines='warn', nrows=2845060)

Issue Description

Read_csv with on_bad_lines AND nrows at the same time appears to not follow the correct on_bad_lines logic. When I run the above example without the nrows argument, I get the following warning:

Skipping line 2845058: '¬' expected after '"'

But running with nrows argument included, it errors out with the following message: (same happens when I use on_bad_lines='skip' instead of 'warn')

Error: '¬' expected after '"'

Expected Behavior

The on_bad_lines logic should continue to work when using nrows so I should see the 'Skipping line' warning.

Installed Versions

INSTALLED VERSIONS

commit : 8dab54d
python : 3.10.6.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19044
machine : AMD64
processor : Intel64 Family 6 Model 154 Stepping 3, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United Kingdom.1252

pandas : 1.5.2
numpy : 1.23.2
pytz : 2022.1
dateutil : 2.8.2
setuptools : 63.2.0
pip : 22.2.2
Cython : None
pytest : None
hypothesis : None
...
xlrd : 2.0.1
xlwt : None
zstandard : None
tzdata : None

@d2thebee d2thebee added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Dec 23, 2022
@lithomas1 lithomas1 added IO CSV read_csv, to_csv Needs Info Clarification about behavior needed to assess issue and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Dec 23, 2022
@lithomas1
Copy link
Member

Please provide a sample file so that we can reproduce this.

Also, this is probably expected for now. (see #50311). Discussion is probably needed before changing this.

@phofl
Copy link
Member

phofl commented Feb 2, 2023

Closing, please ping to reopen when you can provide an example

@phofl phofl closed this as completed Feb 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug IO CSV read_csv, to_csv Needs Info Clarification about behavior needed to assess issue
Projects
None yet
Development

No branches or pull requests

3 participants