Skip to content

feat!: Fail on infinite numbers instead of writing NULL - #636

Merged
krlmlr merged 6 commits into
claude/bind-nonfinite-timesfrom
claude/bind-nonfinite-numbers
Nov 29, 2026
Merged

krlmlr merged 6 commits into
claude/bind-nonfinite-timesfrom
claude/bind-nonfinite-numbers

Conversation

@krlmlr

@krlmlr krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

Stacked on #623. This is the breaking part of the decision on #623 ("Fail on Inf/-Inf in both time and numeric columns"), kept in its own PR as asked.

Before this change, numeric_to_finite() wrote Inf and -Inf in numeric columns as NULL, without a warning. They now fail with "Can't represent N infinite numeric value(s) in column(s) x: use NA for missing values.", on every write path: dbBind(), sqlData(), dbAppendTable() and dbWriteTable(), both with prepared statements and with load_data_local_infile = TRUE. NA and NaN are still written as NULL. The message labels columns as #623's errors do, by name or by position, through a shared column_labels() helper.

The commit body carries the NEWS line: "Binding Inf or -Inf in numeric columns now fails instead of writing NULL."

Tests

tests/testthat/test-bind-nonfinite.R gains tests for numeric columns through dbBind(), sqlData() and load_data_local_infile. Each failing write checks that the table still has 0 rows. tests/testthat/test-dbWriteTable.R's "converts NaN and Inf to NULL" is split into "converts NaN to NULL" and "fails on Inf".

The local test server is down, so the database tests have not run here yet; CI runs them. The package builds. The error texts, column labels, and the handling of NA, NaN, POSIXlt, AsIs and integer64 were checked by calling numeric_to_finite(), sql_data() and csv_quote() directly.

Accepted limitations

Session: https://claude.ai/code/session_01Hr1rd5PUWgaCJzotWt9NhJ


Generated by Claude Code

Binding `Inf` or `-Inf` in numeric columns now fails instead of writing `NULL`,
in `dbBind()`, `sqlData()`, `dbWriteTable()`, and `dbAppendTable()`,
also with `load_data_local_infile = TRUE`.
`NaN` and `NA` are still written as `NULL`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd5PUWgaCJzotWt9NhJ

krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member Author

Superseded: Accepted limitations

The clean review found nothing above Low. It confirmed that no DBItest spec writes Inf, that integer, integer64, logical and character columns pass through untouched, and that NaN is still written as NULL.

One Low is fixed anyway, because it could lose data. dbWriteTable(overwrite = TRUE) dropped and recreated the old table before the check failed. DDL commits implicitly, so the old table was gone. dbWriteTable() now checks the data before the transaction starts (e375e23 in #623, 11c1277 here).

  • R/coerce.R: unnamed parameters are labeled by position in the error, e.g. "column(s) Add vignette discussing how to use google cloud sql #2". Relevance: low. Reviewer confidence: high.
  • NEWS.md still says, for an older release, that NaN and Inf are converted to NULL. The NEWS line of this PR's commit supersedes it. Relevance: low. Reviewer confidence: high.
  • The local test server is down, so the database tests of this PR, including the one that checks the old table survives, have not run here; CI runs them. Relevance: medium until CI is green. Reviewer confidence: high.

Generated by Claude Code

@krlmlr
krlmlr marked this pull request as ready for review November 29, 2026 14:49
…o claude/bind-nonfinite-numbers

# Conflicts:
#	tests/testthat/test-bind-nonfinite.R
…o claude/bind-nonfinite-numbers

# Conflicts:
#	tests/testthat/test-bind-nonfinite.R

krlmlr commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Accepted limitations

The clean review found nothing above Low. It confirmed that no DBItest spec writes Inf, that integer, integer64, logical and character columns pass through untouched, and that NaN is still written as NULL. Following the review comment on #623, dbWriteTable() computes the data only once (merged here in 76d0d12).


Generated by Claude Code

@krlmlr

krlmlr commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Resolve stack conflicts.

krlmlr commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Done. The latest main (with #632 and #640) is merged into #623 (d12b68b), and #623 into this PR (b0743c7), both without conflicts. No test on main writes Inf outside the files these PRs already update, so there is no semantic conflict either. Both PRs are now only waiting for CI.


Generated by Claude Code

@krlmlr
krlmlr enabled stacked auto-merge (squash) November 29, 2026 17:19
…numbers

Since the data is computed only once, the check runs on the bound
parameters, which label columns by position.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd5PUWgaCJzotWt9NhJ

krlmlr commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

The red smoke test on b0743c7 (job) came from test-dbWriteTable.R:77 ("fails on Inf"). It expected the column name col1 in the error. Since dbWriteTable() computes the data only once, the check runs on the bound parameters, which label columns by position: "Can't represent 2 infinite numeric value(s) in column(s) #1". That is the labeling already listed under the accepted limitations. 2cb2008 drops the column name from the expected message. The error itself is unchanged.


Generated by Claude Code

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants