Skip to content
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

Give more precise warning when passing header=-1 in pandas.read_csv, or don't throw error #27779

Closed
MarcoGorelli opened this issue Aug 6, 2019 · 3 comments · Fixed by #27878
Labels
Error Reporting Incorrect or improved errors from pandas IO CSV read_csv, to_csv
Milestone

Comments

@MarcoGorelli
Copy link
Member

MarcoGorelli commented Aug 6, 2019

Code Sample, a copy-pastable example if possible

from io import StringIO
import pandas as pd

print(f"Using pandas version {pd.__version__}")
pd.read_csv(StringIO('spam'), header=-1)

Using pandas version 0.25.0


OverflowError

Problem description

In previous versions of pandas (e.g. 0.24.2), this would have worked fine. Instead, now, one has to pass header=None. However, when working with old code after having updated pandas, it may be unclear where the problem lies.

Expected Output

      0
0  spam

Output of pd.show_versions()

[paste the output of pd.show_versions() here below this line]
INSTALLED VERSIONS

commit : None
python : 3.7.3.final.0
python-bits : 64
OS : Linux
OS-release : 4.15.0-55-generic
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_GB.UTF-8
LOCALE : en_GB.UTF-8

pandas : 0.25.0
numpy : 1.16.4
pytz : 2019.1
dateutil : 2.8.0
pip : 19.1.1
setuptools : 41.0.1
Cython : 0.29.12
pytest : 4.5.0
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.10.1
IPython : 7.7.0
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : 3.1.0
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 0.13.0
pytables : None
s3fs : 0.2.1
scipy : 1.3.0
sqlalchemy : 1.3.5
tables : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None

@MarcoGorelli MarcoGorelli changed the title Give more precise warning when passing header=-1 in pandas.read_csv Give more precise warning when passing header=-1 in pandas.read_csv, or don't throw error Aug 6, 2019
@mroeschke mroeschke added Error Reporting Incorrect or improved errors from pandas IO CSV read_csv, to_csv labels Aug 6, 2019
@TomAugspurger TomAugspurger added this to the Contributions Welcome milestone Aug 9, 2019
@TomAugspurger
Copy link
Contributor

@MarcoGorelli are you interested in submitting a pull request?

@MarcoGorelli
Copy link
Member Author

MarcoGorelli commented Aug 9, 2019 via email

@MarcoGorelli
Copy link
Member Author

MarcoGorelli commented Aug 14, 2019

I've attempted to fix this by modifying validate_header from pandas/io/common.py to check that header=-1 wasn't passed and to raise an error advising user to pass header=None instead if their data has no header, along with an accompanying test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas IO CSV read_csv, to_csv
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants