Skip to content

Commit 6e3c3da

Browse files
committed
gdalcompare: do not emit exception when all pixels are invalid
Fixes #12137
1 parent 97d1bb3 commit 6e3c3da

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

autotest/pyscripts/test_gdalcompare.py

+34
Original file line numberDiff line numberDiff line change
@@ -320,3 +320,37 @@ def test_gdalcompare_different_overview(tmp_vsimem, captured_print, source_filen
320320
)
321321
== 1
322322
)
323+
324+
325+
###############################################################################
326+
# Test case of https://github.com/OSGeo/gdal/issues/12137
327+
328+
329+
def test_gdalcompare_float32_only_nodata(tmp_vsimem):
330+
331+
filename_all_nodata = str(tmp_vsimem / "all_nodata.tif")
332+
ds = gdal.GetDriverByName("GTiff").Create(
333+
filename_all_nodata, 1, 1, 1, gdal.GDT_Float32
334+
)
335+
ds.GetRasterBand(1).SetNoDataValue(0)
336+
ds.Close()
337+
338+
assert (
339+
gdalcompare.find_diff(
340+
filename_all_nodata, filename_all_nodata, options=["SKIP_BINARY"]
341+
)
342+
== 0
343+
)
344+
345+
filename_all_zero = str(tmp_vsimem / "all_zero.tif")
346+
ds = gdal.GetDriverByName("GTiff").Create(
347+
filename_all_zero, 1, 1, 1, gdal.GDT_Float32
348+
)
349+
ds.Close()
350+
351+
assert (
352+
gdalcompare.find_diff(
353+
filename_all_zero, filename_all_nodata, options=["SKIP_BINARY"]
354+
)
355+
== 2
356+
)

swig/python/gdal-utils/osgeo_utils/gdalcompare.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,9 @@ def compare_band(golden_band, new_band, id, options=None):
190190
else:
191191
# check a bit deeper in case of Float data type for which the Checksum() function is not reliable
192192
if golden_band.DataType in (gdal.GDT_Float32, gdal.GDT_Float64):
193-
if golden_band.ComputeRasterMinMax() != new_band.ComputeRasterMinMax():
193+
if golden_band.ComputeRasterMinMax(
194+
can_return_none=True
195+
) != new_band.ComputeRasterMinMax(can_return_none=True):
194196
my_print("Band %s statistics difference:" % 1)
195197
my_print(" Golden: " + str(golden_band.ComputeBandStats()))
196198
my_print(" New: " + str(new_band.ComputeBandStats()))

0 commit comments

Comments
 (0)