Fix open_geotiff(gpu=True) silently dropping on_gpu_failure (#1615)#1622
Merged
brendancol merged 1 commit intoMay 11, 2026
Merged
Conversation
) open_geotiff's GPU branch called read_geotiff_gpu without forwarding on_gpu_failure, so callers wanting strict GPU-failure mode through the dispatcher entry point had no way to enable it. They had to drop down to read_geotiff_gpu directly, defeating the whole point of the auto-dispatch. Same shape as #1561 and #1605: kwargs added to a backend without a matching update to the dispatcher signature. Add on_gpu_failure to open_geotiff with a sentinel default. When gpu=True, forward to read_geotiff_gpu. When gpu=False (or unset), raise ValueError so the kwarg cannot be silently dropped on the CPU or dask path. Tests cover: signature presence, gpu=False rejection (default and explicit), chunks-only rejection, dispatch byte-stability for the default case, and GPU-path end-to-end forwarding (gated on CUDA). Closes #1615.
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a dispatcher/API parity bug in xrspatial.geotiff.open_geotiff where the GPU failure-policy kwarg (on_gpu_failure) was not accepted/forwarded, preventing callers from requesting strict GPU-failure semantics through the public entry point.
Changes:
- Add
on_gpu_failuretoopen_geotiff’s signature (with a sentinel default) and forward it toread_geotiff_gpuwhengpu=True. - Reject
on_gpu_failureup-front whengpu=False(including thechunks=...CPU/dask dispatch), to avoid silent ignoring. - Add a dedicated regression test module covering signature presence, rejection semantics, byte-stable default behavior, and GPU-path forwarding.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
xrspatial/geotiff/__init__.py |
Extends open_geotiff to accept/validate/forward on_gpu_failure; moves sentinel definitions earlier to support sentinel defaults. |
xrspatial/geotiff/tests/test_open_geotiff_on_gpu_failure_1615.py |
Adds regression coverage for the dispatcher kwarg wiring and failure-mode behavior. |
Comments suppressed due to low confidence (1)
xrspatial/geotiff/init.py:516
open_geotiffnow acceptson_gpu_failure, but for.vrtsources it returnsread_vrt(..., gpu=gpu, ...)regardless ofgpu=True, andon_gpu_failureis neither forwarded nor rejected. This meansopen_geotiff('file.vrt', gpu=True, on_gpu_failure='strict')will silently ignore the kwarg (the exact class of bug this PR is fixing). Consider explicitly rejectingon_gpu_failurefor VRT dispatch (even whengpu=True) with a clearValueError, or update the docstring/behavior so it’s never silently dropped.
# ``on_gpu_failure`` is GPU-only. Reject it up front for CPU/dask paths
# rather than silently dropping it once dispatch is decided -- callers
# otherwise have no way to learn that the policy is being ignored.
# ``gpu=False`` (the default) on a ``.vrt`` source still routes through
# ``read_vrt`` below which has no GPU-failure concept, so the same
# rejection rule applies there.
if on_gpu_failure is not _ON_GPU_FAILURE_SENTINEL and not gpu:
raise ValueError(
"on_gpu_failure only applies when gpu=True. "
"Pass gpu=True to enable the GPU pipeline, or drop "
"on_gpu_failure to keep the default CPU path.")
# VRT files (string paths only -- VRT XML references other files on disk)
if isinstance(source, str) and source.lower().endswith('.vrt'):
return read_vrt(source, dtype=dtype, window=window, band=band,
name=name, chunks=chunks, gpu=gpu,
max_pixels=max_pixels)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
open_geotiff(source, gpu=True, ...)silently dropped theon_gpu_failurekwarg. The dispatcher did not declare it, and the GPU branch did not forward it toread_geotiff_gpu. Callers wanting strict GPU-failure semantics through the dispatcher had no way to enable them; they had to bypassopen_geotiffand callread_geotiff_gpudirectly, defeating the auto-dispatch.Same shape as #1561 (kwargs lost in dispatch) and #1605 (
window=/band=lost on the GPU branch). Theon_gpu_failurekwarg was added in PR #1590 (Closes #1560); the dispatcher was not updated then.This PR:
on_gpu_failureto theopen_geotiffsignature with a sentinel default.read_geotiff_gpuwhengpu=True.ValueErrorwhenon_gpu_failureis supplied withgpu=False(default or explicit), or withchunks=N-only. The kwarg only applies to the GPU pipeline; refusing up front matches the patternto_geotiffuses formax_z_erroron non-LERC codecs.on_gpu_failure:read_geotiff_gpuis called without the kwarg, so its own default ('auto') applies.The sentinel definitions (
_GPU_DEPRECATED_SENTINEL,_ON_GPU_FAILURE_SENTINEL) were moved up in the file so they are defined beforeopen_geotiffuses one in its default value.Reproducer
Before this PR:
After this PR:
Test plan
xrspatial/geotiff/tests/test_open_geotiff_on_gpu_failure_1615.pycover: signature presence,gpu=Falserejection (default + explicit),chunks-only rejection, CPU dispatch byte-stability for the default case, dask dispatch byte-stability for the default case, GPU-path end-to-end with'auto'and'strict', invalid-value validation surfaces through the dispatcher on a GPU host, and an invalid-value test that works on CPU-only CI (validation fires before the cupy import).test_gpu_kwarg_rename_1560.py,test_backend_kwarg_parity_1561.py, andtest_gpu_window_band_1605.pyall still pass (30/30).xrspatial/geotiff/tests/suite: 1210 passing on this branch, 7 skipped, 3 pre-existing matplotlib palette failures unrelated to this change (confirmed by reverting__init__.pytoorigin/mainand re-running the palette tests onmain).Closes #1615.