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
import numpy as np
query = """
SELECT
longID
FROM teradata_table
WHERE
longID = 305184080441754059;
"""
dtype = {
"QueryID": np.uint64,
}
with teradatasql.connect(
host=HOST, user=USERNAME, password=PASSWORD, logmech="LDAP"
) as connect:
df = pd.read_sql(query, connect, dtype=dtype)
df.head()
# pandas returns longID 305184080441754048 - close but not quite 305184080441754059
Issue Description
We have trouble when pulling long longID
with 18 digits pandas are incorrectly reading the Teradata value. I also tried using cast(longID as decimal(18, 0))
to help Pandas understand the type of longID
. So far I haven't found a solution how to fix the problem - incorrect value read.
We are using teradatasql
version 20.0.0.24
we can confirm that teradatasql
is working correctly as it gives us the value below when using query specified above: Decimal('305184080441754059')
with teradatasql.connect(
host=HOST, user=USERNAME, password=PASSWORD, logmech="LDAP"
) as con:
with con.cursor() as cur:
cur.execute(query)
for row in cur:
print(f"{row}")
^ this works as expected - so we assume that Teradata SQL library is working correctly.
Expected Behavior
We expect to see 305184080441754059
as longID
in the pandas dataframe.
Installed Versions
pandas : 2.3.0
numpy : 1.26.4
pytz : 2025.1
dateutil : 2.9.0.post0
pip : 25.0.1
Cython : None
sphinx : None
IPython : 8.32.0
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.13.3
blosc : None
bottleneck : None
dataframe-api-compat : None
fastparquet : 2024.11.0
fsspec : 2025.5.1
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : 3.1.5
lxml.etree : 5.4.0
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : 3.1.5
pandas_gbq : None
psycopg2 : 2.9.10
pymysql : None
pyarrow : 20.0.0
pyreadstat : None
pytest : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.15.3
sqlalchemy : 2.0.38
tables : None
tabulate : None
xarray : None
xlrd : None
xlsxwriter : None
zstandard : 0.23.0
tzdata : 2025.2
qtpy : None
pyqt5 : None