Skip to content

BUG: read_sql with integer dtype rounds large ints through float64 (GH#61667) - #71504

Open
jbrockmendel wants to merge 2 commits into
pandas-dev:mainfrom
jbrockmendel:bug-61667
Open

jbrockmendel wants to merge 2 commits into
pandas-dev:mainfrom
jbrockmendel:bug-61667

Conversation

@jbrockmendel

Copy link
Copy Markdown
Member

closes #61667

read_sql/read_sql_query infer each column first and apply dtype= afterwards, so a Decimal column (under the default coerce_float=True) or an integer column containing NULL passes through float64 and loses values beyond 2**53 before an integer dtype ever sees them. Now a column requested as an integer dtype (int64, uint64, Int64, int64[pyarrow], ...) whose values are ints/Decimals is cast directly from the exact values. All other targets keep the existing inference, and a numpy int dtype on a column with NULL still raises IntCastingNaNError as before.

This leaves the default coerce_float behavior alone (GH-63532); the coerce_float docstring note added in GH-66655 now points to an integer dtype as the way to keep such values exact. The ADBC driver path converts to float64 before pandas sees the data and is not changed here (the new test xfails it).

AI disclosure: drafted with Claude Code (claude opus 5.5 (high)), used to investigate, write the fix and tests, and review the branch.

@jbrockmendel jbrockmendel added Bug IO SQL to_sql, read_sql, read_sql_query labels Oct 24, 2026
@jbrockmendel
jbrockmendel marked this pull request as ready for review October 24, 2026 17:19
@jbrockmendel
jbrockmendel force-pushed the bug-61667 branch 2 times, most recently from 048eec3 to 75e742f Compare November 1, 2026 20:54
@jbrockmendel jbrockmendel added this to the 3.2 milestone Nov 8, 2026
jbrockmendel and others added 2 commits November 8, 2026 19:02
…H#61667)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…al Decimals

Only Decimal and int+NULL columns lose precision through inference, so only
those skip it; other int columns keep main's casting behavior.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug IO SQL to_sql, read_sql, read_sql_query

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: pd.read_sql is incorrectly reading long int when connecting to Teradata

1 participant