neo-bumblebee-ai opened a new pull request, #4627:
URL: https://github.com/apache/iceberg-python/pull/4627

   # Rationale for this change
   
   `Table.upsert` reports an unchanged row as updated when the only difference 
is a NaN nested inside a struct, list, or map. `_values_differ` compares flat 
columns with `pc.equal`. Nested types have no Arrow equality kernel, so they 
fall back to Python values from `to_pylist()`, and `float('nan') != 
float('nan')` propagates through dicts, lists, and tuples. The row is rewritten 
and a new snapshot is committed on every upsert. This is the same symptom as 
#4618, on the fallback path that #4622 does not change.
   
   The fallback now walks those Python values and treats NaN as equal to NaN. 
Two nulls stay equal. Null and NaN stay different, in both directions. A real 
change next to a nested NaN is still an update.
   
   This stands on its own relative to #4622. That change teaches the Arrow 
kernel path to treat two flat NaNs as equal. This change only replaces the 
Python fallback used when `pc.equal` raises. The diffs apply together: flat 
NaNs are handled by `pc.is_nan`, nested NaNs by the walk. Float16 also uses 
this fallback (`pc.equal` has no half-float kernel), so two float16 NaNs 
compare equal as well.
   
   ## Are these changes tested?
   
   Yes. New tests in `tests/table/test_upsert.py` failed before the change and 
pass after:
   
   - `test_get_rows_to_update_treats_nested_nans_as_equal`: struct, list, map, 
and a struct that contains a list. A row that differs only by nested NaN is not 
an update; a real change in the same column still is.
   - `test_get_rows_to_update_detects_nested_nan_transitions`: number-to-NaN, 
NaN-to-number, null-to-NaN, and NaN-to-null still count as updates for struct, 
list, and mixed values. A NaN-to-NaN row in the same batch does not.
   - `test_upsert_unchanged_frame_with_nested_nan`: re-upserting the same frame 
gives `rows_updated=0` and the snapshot count stays at 1. A later upsert that 
changes a nested field still reports `rows_updated=1`.
   
   `make lint` passes. `uv run python -m pytest tests/table/test_upsert.py`: 30 
passed.
   
   ## Are there any user-facing changes?
   
   Yes, a behavior fix. `upsert` no longer reports updates, or writes new 
snapshots, for rows whose only difference is a NaN nested in a struct, list, or 
map. No API changes.
   
   AI disclosure: this change was developed with AI assistance; I reviewed and 
tested it and can explain every line.
   
   Closes #4623
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to