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

Uninformative error when parsing numbers with a non-standard n/a value #41117

Open
2 of 3 tasks
ghost opened this issue Apr 23, 2021 · 3 comments
Open
2 of 3 tasks

Uninformative error when parsing numbers with a non-standard n/a value #41117

ghost opened this issue Apr 23, 2021 · 3 comments
Labels
Bug Error Reporting Incorrect or improved errors from pandas IO CSV read_csv, to_csv

Comments

@ghost
Copy link

ghost commented Apr 23, 2021

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of pandas.
  • (optional) I have confirmed this bug exists on the master branch of pandas.

Code Sample

data.csv

key,value
a,1.234
b,"1,234.00"
c,":"

Reading the data works ok without parsing the numbers

>>> pd.read_csv('data.csv')
  key     value
0   a     1.234
1   b  1,234.00
2   c         :

When parsing numbers it fails even when the correct thousand separator is set:

>>> pd.read_csv('data.csv', dtype={'value': float}, thousands=',')
ValueError: could not convert string to float: '1,234.00'

However, with the right N/A value setting it works

pd.read_csv('data.csv', dtype={'value': float}, thousands=',', na_values=':')
  key     value
0   a     1.234
1   b  1234.000
2   c       NaN

Problem description

I think the error message saying that pandas could not convert value "1,234.00" to a number is uninformative as the error is rather in the missing value ":".

Might be related to #2570.

Expected Output

I’d expect the error message should be about the non-parsable value ":".

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 2cb9652
python : 3.7.10.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.18362
machine : AMD64
processor : Intel64 Family 6 Model 142 Stepping 10, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.None

pandas : 1.2.4
numpy : 1.20.2
pytz : 2021.1
dateutil : 2.8.1
pip : 21.0.1
setuptools : 52.0.0.post20210125
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 : 7.22.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.4.1
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : 1.6.2
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

@ghost ghost added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 23, 2021
@phofl phofl added IO CSV read_csv, to_csv and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 23, 2021
@lithomas1 lithomas1 added the Error Reporting Incorrect or improved errors from pandas label Apr 24, 2021
@KenilMehta
Copy link
Contributor

I would like to help solving this issue. Is this open for contributions?

@lilisako
Copy link

It's been more than 2 weeks since the last comment posted here. Can I take this issue?

@KenilMehta
Copy link
Contributor

I am not working on it.

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

No branches or pull requests

4 participants