Fix read_vrt dropping SimpleSource <NODATA>0</NODATA> (#1655)#1663
Merged
Conversation
The per-source nodata fallback used `src.nodata or nodata`, and Python treats `0.0` as falsy. A SimpleSource that declared `<NODATA>0</NODATA>` silently picked up the band-level `<NoDataValue>` (or `None` when none was set), so pixels equal to 0.0 in the source file survived as valid data instead of being masked to NaN. The in-code comment described the behaviour as "backward compatibility" but the result is silent data corruption on VRTs that mosaic sources using 0 as a sentinel (a common remote-sensing convention). Switch to an explicit `is not None` check so a legitimate zero sentinel survives the fallback. Add `test_vrt_source_nodata_zero_1655.py` covering five cases: source NODATA=0 with no band fallback, integer XML literal, non-zero unchanged, band-level NoDataValue=0 still honoured when no per-source NODATA is set, and per-source precedence over a different band-level sentinel.
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.
Summary
Closes #1655.
xrspatial.geotiff._vrt.read_vrtsilently treated<NODATA>0</NODATA>on aSimpleSourceas if the element were absent. The per-source nodata fallback usedsrc.nodata or nodata; Python evaluates0.0 or <anything>to<anything>because0.0is falsy. The in-code comment described the behaviour as "backward compatibility" but the result is silent data corruption on VRTs that mosaic sources using 0 as a sentinel (a common remote-sensing convention for unsigned imagery).Switch to an explicit
is not Nonecheck so a legitimate zero sentinel survives the fallback. The behaviour now matches the per-source nodata semantics that GDAL applies.Test plan
test_vrt_source_nodata_zero_1655.py(5 tests): source NODATA=0 with no band fallback, integer XML literal<NODATA>0</NODATA>, non-zero unchanged, band-level<NoDataValue>0</NoDataValue>still honoured, per-source NODATA precedence over a different band sentinel.Notes
Found via
/deep-sweepaccuracy pass 19 on thegeotiffmodule. State file updated in the same commit.