Skip to content

Rename read_geotiff_gpu gpu kwarg to on_gpu_failure (#1560)#1590

Merged
brendancol merged 3 commits into
mainfrom
issue-1560
May 11, 2026
Merged

Rename read_geotiff_gpu gpu kwarg to on_gpu_failure (#1560)#1590
brendancol merged 3 commits into
mainfrom
issue-1560

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

Summary

read_geotiff_gpu's gpu kwarg shares a name with the boolean gpu= on open_geotiff / to_geotiff / read_vrt but accepts {'auto', 'strict'} — it controls failure policy on the GPU path, not whether to use the GPU. Calling read_geotiff_gpu(path, gpu=True) raised the unhelpful ValueError: gpu must be 'auto' or 'strict', got True.

Rename to on_gpu_failure, keep gpu= as a deprecation shim:

  • on_gpu_failure='auto' | 'strict' is the canonical name.
  • gpu= still works, emits DeprecationWarning that names the new kwarg and explains the rename.
  • Passing both raises TypeError.
  • Validation error references on_gpu_failure so the rename is discoverable from the traceback.

Closes #1560.

Test plan

  • New tests in xrspatial/geotiff/tests/test_gpu_kwarg_rename_1560.py cover: invalid value, deprecation warning on gpu=, TypeError when both passed, gpu=True no longer raises misleading "got True" error
  • Existing test_gpu_strict_fallback_1516.py still passes — uses gpu='strict' via the shim (emits DeprecationWarning as expected)
  • Full xrspatial/geotiff/tests/ suite: 357 passing (one matplotlib palette test fails identically on main — unrelated)

The kwarg shared a name with the boolean gpu= on open_geotiff /
to_geotiff / read_vrt but carried a different value space ('auto' or
'strict'). Calling read_geotiff_gpu(path, gpu=True) -- the natural
mental model after using open_geotiff(path, gpu=True) -- raised
"gpu must be 'auto' or 'strict', got True", obscuring the rename and
forcing readers to dig through the source to learn the correct values.

Rename to on_gpu_failure and keep gpu= as a deprecation shim:

- on_gpu_failure: canonical name, same {'auto', 'strict'} value space.
- gpu: still accepted; emits DeprecationWarning that points to the new
  name and explains why the rename happened.
- Passing both raises TypeError to avoid silently picking one.
- Validation error message names on_gpu_failure so the rename is
  discoverable from the traceback.

Existing test_gpu_strict_fallback_1516.py keeps using gpu='strict' via
the shim (with DeprecationWarning, as expected). One assertion that
hardcoded the old error string is updated to the new wording.

Module docstring updated to reference on_gpu_failure='strict' as the
example.
@github-actions github-actions Bot added the performance PR touches performance-sensitive code label May 11, 2026
@brendancol brendancol requested a review from Copilot May 11, 2026 15:12
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR resolves API confusion in xrspatial.geotiff.read_geotiff_gpu by renaming its gpu={'auto','strict'} failure-policy keyword to on_gpu_failure, while keeping gpu= as a deprecated alias to preserve backward compatibility (issue #1560).

Changes:

  • Rename read_geotiff_gpu(..., gpu=...) (failure policy) to read_geotiff_gpu(..., on_gpu_failure=...) and add a deprecation shim for gpu=.
  • Update validation errors to reference on_gpu_failure to make the rename discoverable from tracebacks.
  • Add/adjust tests covering the rename, deprecation warning behavior, and updated validation messaging.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
xrspatial/geotiff/__init__.py Introduces on_gpu_failure kwarg, keeps gpu= as deprecated alias, updates docs/error messages.
xrspatial/geotiff/tests/test_gpu_strict_fallback_1516.py Updates existing test to expect the new validation error text while suppressing deprecation warnings.
xrspatial/geotiff/tests/test_gpu_kwarg_rename_1560.py Adds regression tests for the rename/deprecation/type error and improved validation messaging.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread xrspatial/geotiff/__init__.py Outdated
Comment on lines +1883 to +1887
# refuse rather than silently picking one.
if on_gpu_failure != 'auto':
raise TypeError(
"read_geotiff_gpu: pass either 'on_gpu_failure' or the "
"deprecated 'gpu' alias, not both.")
Comment on lines +55 to +61
with warnings.catch_warnings():
# Suppress the deprecation noise; we only care that the value
# passes validation and the call proceeds to the file-read stage
# (which will fail with a missing-file error, not a ValueError).
warnings.simplefilter("ignore", DeprecationWarning)
with pytest.raises((FileNotFoundError, OSError, ValueError)) as exc_info:
read_geotiff_gpu("/nonexistent.tif", gpu='strict')
Copilot caught a hole in the both-supplied check: the old guard
``if on_gpu_failure != 'auto'`` only fired when the new kwarg was
non-default, so calls like ``on_gpu_failure='auto', gpu='strict'`` (or
``on_gpu_failure='auto', gpu='auto'``) silently accepted the deprecated
value, contradicting the documented contract.

Use a sentinel for both kwargs so the both-supplied case is rejected
regardless of values. Add parametrized regression tests for the three
previously-silent value combinations.

Also widen the accepted-exceptions tuple in
test_gpu_alias_accepts_old_values_without_validation_error to include
ImportError, so it stays meaningful in CPU-only CI (where ``import
cupy`` raises after validation passes).
@brendancol brendancol merged commit 672ebfc into main May 11, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance PR touches performance-sensitive code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

geotiff: gpu keyword has three incompatible value spaces across the public API

2 participants