You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using a csv file which has an extra first line (e.g. the attached file "csv_with_extra_first_line.csv"), the above code raises an EmptyDataError in pandas 1.5.0, but behaves as expected in 1.4.4 and earlier. See stacktrace:
The following conditions have to be met for the issue to manifest:
call to open() with encoding="utf-8" (behaves as expected without encoding specified)
There have to be prior calls to the file handle: f.readline() or similar (file handle with encoding, but no call to f.readline() and option skiprows=1 to read_csv is also fine)
The default engine has to be used. engine="python" also works as expected.
In pandas 1.4.4 and earlier, the code behaves as expected (see below).
The issue is present both on Windows (see version below) and linux (latest and 3.8 python docker image).
Content of the attached file:
This line will be read first by f.readline()
1,2
1,2
1,2
Expected Behavior
The csv file should parse as it would with pd.read_csv("csv_with_extra_first_line.csv", skiprows=1), which yields the following:
1 2
0 1 2
1 1 2
Installed Versions
INSTALLED VERSIONS
------------------
commit : 87cfe4e
python : 3.10.7.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19044
machine : AMD64
processor : Intel64 Family 6 Model 158 Stepping 10, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : de_DE.cp1252
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
Issue Description
Using a csv file which has an extra first line (e.g. the attached file "csv_with_extra_first_line.csv"), the above code raises an
EmptyDataError
in pandas 1.5.0, but behaves as expected in 1.4.4 and earlier. See stacktrace:The following conditions have to be met for the issue to manifest:
open()
withencoding="utf-8"
(behaves as expected without encoding specified)f.readline()
or similar (file handle with encoding, but no call tof.readline()
and optionskiprows=1
toread_csv
is also fine)engine="python"
also works as expected.In pandas 1.4.4 and earlier, the code behaves as expected (see below).
The issue is present both on Windows (see version below) and linux (latest and 3.8 python docker image).
Content of the attached file:
Expected Behavior
The csv file should parse as it would with
pd.read_csv("csv_with_extra_first_line.csv", skiprows=1)
, which yields the following:Installed Versions
pandas : 1.5.0
numpy : 1.23.3
pytz : 2022.2.1
dateutil : 2.8.2
setuptools : 60.2.0
pip : 21.3.1
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
tzdata : None
The text was updated successfully, but these errors were encountered: