Repository navigation
Fix upsert treating NaN rows as changed (#4618) - #4622
Open
ksaiharshavinay wants to merge 2 commits into
Open
ksaiharshavinay wants to merge 2 commits into
ksaiharshavinay wants to merge 2 commits into
Conversation
pc.equal never matches NaN to NaN, so _values_differ reported a row as changed whenever a float column held NaN on both sides, and re-upserting identical data rewrote the row and committed two snapshots. Treat two NaNs in a floating-point column as equal, the same way two nulls are already treated.
Fokko
approved these changes
Dec 4, 2026
Fokko
left a comment
Contributor
There was a problem hiding this comment.
LGTM, thanks @ksaiharshavinay! I verified that NaN to NaN rows no longer count as updates, and that number to NaN, NaN to number, null to NaN and NaN to null transitions are all still reported. Would you mind filing the follow-up for NaN nested in structs/lists (and float16, which also goes through the Python fallback), since that path still treats them as changed? Thanks @KartikGupta2007 for the report too 🙌
1 of 3 tasks
This was referenced Dec 5, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rationale for this change
Table.upserttreats an unchanged row as updated when a float column holds NaN:_values_differcompares withpc.equal, where NaN never equals NaN, so re-upserting identical data reportsrows_updated=1and commits two extra snapshots. Two nulls are already treated as equal; this extends the same treatment to two NaNs for floating-point columns. Eachis_nanresult is filled withFalsefirst, becauseis_nan(null)is null and would otherwise mask a genuine null-to-NaN change. Thanks to @KartikGupta2007 for the report and the repro script.Scope note: NaN nested inside struct/list/map values still compares through the Python fallback path and counts as changed. That is a separate path from the one reported here, so I left it out of this PR; happy to file it as a follow-up.
Are these changes tested?
Yes. Three new tests in
tests/table/test_upsert.py, each verified to fail on main and pass with this change:test_get_rows_to_update_treats_nans_as_equal— a NaN-to-NaN row is not returned as an update; a changed row still is.test_get_rows_to_update_detects_nan_transitions— number-to-NaN, NaN-to-number, null-to-NaN and NaN-to-null all still count as updates.test_upsert_unchanged_frame_with_nan_row— the reported scenario end to end: re-upserting the same frame givesrows_updated=0and the snapshot count stays at 1.The full
tests/tableunit suite shows the same pass/fail set as on main (the failures there are pre-existing environment issues in my sandbox, unrelated to this change). Lint via the repo's prek hooks (ruff, ruff-format, mypy strict, codespell) passes on both changed files.Are there any user-facing changes?
Yes — a behavior fix:
upsertno longer reports updates, or writes new snapshots, for rows whose only "difference" is a NaN in a float column. No API changes. (This looks like it wants the changelog label; I can't add labels myself.)Disclosure: I work with AI assistance and review everything myself before posting.