Bug: read_csv losing precision when reading Int64 data with N/A values · Issue #32134 · pandas-dev/pandas (original) (raw)
Code Sample
import pandas as pd
import numpy as np
from io import StringIO
TESTDATA1 = StringIO("""col1;col2
1;123
2;456
3;1582218195625938945
""")
TESTDATA2 = StringIO("""col1;col2
1;123
2;
3;1582218195625938945
""")
D1 = pd.read_csv(TESTDATA1, sep=";", dtype={'col2':'Int64'})
D2 = pd.read_csv(TESTDATA2, sep=";", dtype={'col2':'Int64'})
D1['col2']
D2['col2']
D1.loc[2,'col2'] == D2.loc[2,'col2']
Yields :
>>> D1['col2']
0 123
1 456
2 1582218195625938945
Name: col2, dtype: Int64
>>> D2['col2']
0 123
1 <NA>
2 1582218195625938944
Name: col2, dtype: Int64
>>> D1.loc[2,'col2'] == D2.loc[2,'col2']
False
Problem description
When pd.read_csv reads a column with Nullable Int64 data, and the column contains missing values (N/A), the precision on other values in that column is not maintained.
Expected Output
>>> D1['col2']
0 123
1 456
2 1582218195625938945
Name: col2, dtype: Int64
>>> D2['col2']
0 123
1 <NA>
2 1582218195625938945
Name: col2, dtype: Int64
>>> D1.loc[2,'col2'] == D2.loc[2,'col2']
True
Output of pd.show_versions()
>>> pd.show_versions()
INSTALLED VERSIONS
commit : None
python : 3.7.3.final.0
python-bits : 64
OS : Linux
OS-release : 4.18.0-3-amd64
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : None
LOCALE : en_US.UTF-8
pandas : 1.0.1
numpy : 1.18.1
pytz : 2019.3
dateutil : 2.8.1
pip : 18.1
setuptools : 40.8.0
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
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pytest : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None
numba : None