Description
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
s=pd.HDFStore('/tmp/test.h5')
df=pd.DataFrame(zip(['a','b','c','d'],[-9223372036854775801, -9223372036854775802,-9223372036854775803,123]), columns=['x','y'])
s.append('data',df,data_columns=True, index=False)
s.close()
s=pd.HDFStore('/tmp/test.h5')
s.select('data', where='y==-9223372036854775801')
Issue Description
The above code will return no records which is obviously wrong. The issue is caused by the below in pandas/core/computation/pytables.py (function convert_value of class BinOp). Precision is lost after converting large integer to float and then back to integer:
elif kind == "integer":
v = int(float(v))
return TermValue(v, v, kind)
Expected Behavior
return the matched row instead of empty dataframe
Installed Versions
INSTALLED VERSIONS
commit : 37ea63d
python : 3.10.6.final.0
python-bits : 64
OS : Linux
OS-release : 5.15.0-72-generic
Version : #79-Ubuntu SMP Wed Apr 19 08:22:18 UTC 2023
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 2.0.1
numpy : 1.23.5
pytz : 2022.1
dateutil : 2.8.2
setuptools : 59.6.0
pip : 22.0.2
Cython : 0.29.33
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.8.0
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 7.31.1
pandas_datareader: None
bs4 : 4.10.0
bottleneck : None
brotli : 1.0.9
fastparquet : None
fsspec : 2023.1.0
gcsfs : None
matplotlib : 3.5.1
numba : 0.56.4
numexpr : 2.8.4
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 12.0.0
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.8.0
snappy : None
sqlalchemy : None
tables : 3.8.0
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None