Skip to content

geotiff: cover gil_friendly kwarg behaviour added in #1826 (#1830)#1834

Open
brendancol wants to merge 2 commits into
mainfrom
deep-sweep-test-coverage-geotiff-2026-05-13-3170714-01
Open

geotiff: cover gil_friendly kwarg behaviour added in #1826 (#1830)#1834
brendancol wants to merge 2 commits into
mainfrom
deep-sweep-test-coverage-geotiff-2026-05-13-3170714-01

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

Summary

What the new tests pin

  • deflate_compress(gil_friendly=True) bypasses libdeflate even when the optional deflate PyPI binding is installed; gil_friendly=False keeps using it; both round-trip through stdlib zlib.decompress at levels 1/6/9.
  • The fallback UserWarning fires exactly once when libdeflate is missing, is suppressed when the module-global latch is set, and is not re-emitted across subsequent calls (no per-call spam).
  • compress(DEFLATE, gil_friendly=...) forwards the flag; the flag is a no-op for LZW/PackBits/zstd/lz4/none.
  • _write_stripped parallel path passes gil_friendly=True on every strip; the sequential path leaves it at False. Same matrix for _write_tiled.
  • _prepare_strip and _prepare_tile forward the kwarg into deflate_compress. The parallel _write_tiled branch passes True positionally to _prepare_tile, pinned via the function signature.
  • End-to-end round-trip across both strip/tile and parallel/sequential modes.

Verification

  • Local: pytest xrspatial/geotiff/tests/test_gil_friendly_kwarg_1830.py -> 20 passed.
  • Adjacent suites still green: test_parallel_writer_1800.py + test_compression.py + test_compression_level.py + test_streaming_write.py + new file -> 99 passed.
  • Mutation checks:
    • Drop the and not gil_friendly guard in _compression.py:137 -> 2 tests red (test_deflate_compress_gil_friendly_true_bypasses_libdeflate, test_compress_forwards_gil_friendly_to_deflate).
    • Flip the writer's gil_friendly=True to False in _write_stripped -> test_write_stripped_parallel_path_uses_gil_friendly red.
    • Delete the fallback warnings.warn block -> test_deflate_compress_fallback_warning_fires_when_libdeflate_missing red.

Test plan

  • pytest xrspatial/geotiff/tests/test_gil_friendly_kwarg_1830.py -q -> 20 passed on a host with deflate installed.
  • CI: same file runs on a host without deflate -- the libdeflate-installed tests skip cleanly, the fallback tests stay green.

PR #1826 added a ``gil_friendly`` flag to ``deflate_compress`` /
``compress`` / ``_prepare_strip`` / ``_prepare_tile`` /
``_compress_block``. The flag forces deflate through stdlib
``zlib.compress`` (GIL-releasing) when set, so the writer's parallel
strip/tile paths actually scale across 8 threads (~5x vs ~1.2x with the
GIL-holding libdeflate binding). Existing tests covered round-trip
correctness and that the thread pool dispatched, but nothing observed
which deflate backend ran, which strip/tile branch passed which flag
value, or that the one-shot fallback ``UserWarning`` fired when the
optional ``deflate`` package was missing.

20 new tests pin every layer of the new contract:

- ``deflate_compress(gil_friendly=True)`` bypasses libdeflate; the
  default keeps using libdeflate when installed; both directions
  round-trip through stdlib ``zlib.decompress`` at levels 1/6/9.
- The fallback UserWarning fires exactly once when libdeflate is
  missing, stays suppressed when the latch is set, and reuses the
  latch across subsequent calls (no per-call spam).
- ``compress(DEFLATE, gil_friendly=...)`` forwards the flag to the
  codec; the flag is a no-op for LZW/PackBits/zstd/lz4/none.
- ``_write_stripped`` parallel path passes ``gil_friendly=True`` on
  every strip; the sequential path leaves it at the default ``False``.
- ``_write_tiled`` parallel path passes ``True`` positionally; the
  sequential path leaves it at ``False``. ``_prepare_strip`` and
  ``_prepare_tile`` forward the kwarg through to ``deflate_compress``.
- End-to-end round-trip across both parallelism modes (strip/tile,
  small/large).

Mutation checks confirm coverage: dropping the ``and not gil_friendly``
guard in ``_compression.py`` flips two tests red; flipping the
writer's ``gil_friendly=True`` to ``False`` flips the parallel-path
test red; deleting the warning flips the warning-fires test red.

Closes #1830
@github-actions github-actions Bot added the performance PR touches performance-sensitive code label May 14, 2026
The macOS 3.12 CI runner ships without the optional ``lz4`` package, so
the unconditional LZ4 row in ``test_compress_gil_friendly_ignored_for_non
_deflate_codecs`` raised ImportError before reaching the gil_friendly
assertion. Skip the LZ4 row when the codec is unavailable; the rest of
the non-deflate codecs (none, packbits, lzw, zstd) still cover the
parity check.
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

Adds direct GeoTIFF tests for the gil_friendly compression flag introduced in PR #1826, focusing on deflate backend selection and writer forwarding behavior.

Changes:

  • Adds tests for deflate_compress and compress backend routing with gil_friendly=True/False.
  • Adds tests for stripped/tiled writer paths forwarding the flag correctly.
  • Adds end-to-end deflate round-trip coverage across sequential and parallel strip/tile modes.

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

Comment on lines +324 to +325
# Writer call-site verification: _write_stripped / _write_tiled /
# write_streaming pass the right gil_friendly value into the codec.
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.

Test: cover gil_friendly kwarg behaviour in geotiff writer/compression

2 participants