Skip to content

geotiff: reject write_geotiff_gpu jpeg by default, add opt-in flag (#1845)#1849

Merged
brendancol merged 1 commit into
xarray-contrib:mainfrom
brendancol:issue-1845
May 14, 2026
Merged

geotiff: reject write_geotiff_gpu jpeg by default, add opt-in flag (#1845)#1849
brendancol merged 1 commit into
xarray-contrib:mainfrom
brendancol:issue-1845

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

Closes #1845.

Summary

  • to_geotiff rejects compression='jpeg' because the encoder skips the TIFF JPEGTables tag (347); files produced that way fail in libtiff, GDAL, and rasterio.
  • write_geotiff_gpu sat in the same module and silently accepted the same kwarg, producing the same broken format.
  • Reject compression='jpeg' on write_geotiff_gpu by default with the same wording.
  • Add allow_internal_only_jpeg: bool = False so callers who want the experimental internal-reader-only path can opt in. When the flag is set, the write proceeds and emits a GeoTIFFFallbackWarning at call time.

Migration

Callers currently relying on write_geotiff_gpu(..., compression='jpeg') get a ValueError after this PR. Two options:

  • Switch to a codec other readers can decode: 'deflate', 'zstd', 'lzw'.
  • Pass allow_internal_only_jpeg=True to keep the existing behaviour. The file will still not round-trip through GDAL or rasterio; the warning is the contract.

Test plan

  • New test module test_gpu_jpeg_interop_reject_issue_D_1845.py: 3 CPU-only rejection tests plus 2 GPU-gated opt-in tests, all pass.
  • Four existing GPU JPEG tests in test_gpu_writer_compression_modes_2026_05_11.py updated to pass the opt-in flag; all pass.
  • Signature parity tests (test_signature_parity_1631, test_signature_annotations_*, test_backend_kwarg_parity_1561): 46 passed.
  • Compression docstring test pinning the codec list still passes.
  • Full xrspatial/geotiff/tests/ run: pre-existing failures only (matplotlib RecursionError in test_features, predictor2 big-endian GPU tests, one tile-size GPU test) — all reproduce on origin/main.

… flag (xarray-contrib#1845)

The CPU writer to_geotiff already raised ValueError for compression='jpeg'
because the encoder skips the TIFF JPEGTables tag (347) and the resulting
files are unreadable by libtiff, GDAL, and rasterio. write_geotiff_gpu sat
in the same module and silently accepted the same kwarg, producing the same
broken format. Two public entry points in the same module disagreed about
the same codec.

Reject compression='jpeg' on write_geotiff_gpu by default with the same
wording to_geotiff uses. Add allow_internal_only_jpeg=False to keep the
experimental internal-reader-only path reachable for callers who want it;
when the flag is set the writer proceeds and emits a
GeoTIFFFallbackWarning so the round-trip caveat is loud at call time.

Updates the four existing GPU JPEG tests to pass the opt-in flag and adds
a new test module covering the rejection (CPU-only, no CUDA needed) and
the opt-in warning behaviour.
@github-actions github-actions Bot added the performance PR touches performance-sensitive code label May 14, 2026
@brendancol brendancol requested a review from Copilot May 14, 2026 17:00
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

Aligns write_geotiff_gpu with to_geotiff by rejecting compression='jpeg' by default (both writers produce TIFFs missing the JPEGTables tag and unreadable by libtiff/GDAL/rasterio), while adding an opt-in allow_internal_only_jpeg flag that proceeds with the internal-only encode and emits a GeoTIFFFallbackWarning.

Changes:

  • Add allow_internal_only_jpeg: bool = False parameter to write_geotiff_gpu with rejection + warning logic.
  • Update docstring to document the rejection, opt-in, and interop caveat.
  • Add new test module for rejection/opt-in behavior and update existing GPU JPEG tests to pass the flag.

Reviewed changes

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

File Description
xrspatial/geotiff/init.py Adds opt-in flag, rejection ValueError, and fallback warning for JPEG path; docstring updated.
xrspatial/geotiff/tests/test_gpu_jpeg_interop_reject_issue_D_1845.py New tests covering default rejection, message parity, case insensitivity, opt-in warning, and non-JPEG no-op.
xrspatial/geotiff/tests/test_gpu_writer_compression_modes_2026_05_11.py Updates existing GPU JPEG tests to set the opt-in flag and assert the warning.

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

@brendancol brendancol merged commit dd31bf7 into xarray-contrib:main May 14, 2026
16 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.

write_geotiff_gpu emits JPEG TIFFs that other readers reject

2 participants