geotiff: stamp _xrspatial_geotiff_contract=1 on every read (#1984)#2003
Merged
Conversation
PR 3 of 7 on issue #1984. Adds a contract-version marker attr (``_xrspatial_geotiff_contract``) to every DataArray returned by an xrspatial geotiff read path so downstream code can identify which attrs-contract revision produced an array. The value lives as a module-level constant ``_ATTRS_CONTRACT_VERSION`` in ``_attrs.py``. The eager numpy, dask+numpy, GPU, dask+GPU, and the COG/HTTP path all funnel through ``_populate_attrs_from_geo_info``, so one stamp there covers four backends. The VRT backends in ``_backends/vrt.py`` build their attrs dict directly and stamp the version inline; both the eager and chunked VRT paths reuse the same constant so the value stays in lockstep when it is later bumped. Adds ``test_attrs_contract_version_1984.py`` with one assertion per read path (eager, dask, GPU, dask+GPU, VRT eager, VRT chunked) plus a pin on the constant value.
Contributor
Author
PR Review: geotiff: stamp _xrspatial_geotiff_contract=1 on every readBlockers (must fix before merge)None. Suggestions (should fix, not blocking)
Nits (optional improvements)
What looks good
Checklist
|
- _attrs.py docstring: noted that the stamp overwrites any pre-existing value on the passed-in attrs dict; callers pass freshly built dicts. - _backends/vrt.py (eager + chunked): added inline comments pointing at _populate_attrs_from_geo_info as the canonical stamp site, so future maintainers know why the helper is bypassed in the VRT path.
2 tasks
brendancol
added a commit
that referenced
this pull request
May 18, 2026
* geotiff: add attrs canonical-tier locking test (#1984) PR 4 of 7 from the attrs-contract plan in #1984. Adds test_attrs_contract_canonical_1984.py: a single fixture that exercises every canonical attr (crs, crs_wkt, transform, nodata, raster_type, extra_tags, gdal_metadata, gdal_metadata_xml, x_resolution / y_resolution / resolution_unit, _xrspatial_geotiff_contract), round-trips it through to_geotiff -> open_geotiff, and asserts presence + value per key. Sibling locking tests already cover the other tiers: aliases (#2002), pass-through (#2004), and per-backend stamping of the contract version (#2003). The canonical assertion list is what #1985 (parity matrix) and #1986 (round-trip invariants) will import. No production-code changes. * geotiff: address review on attrs canonical-tier locking test Addresses self-review on PR #2009: * Add per-backend canonical-key presence parametrisation (eager-numpy, dask-numpy, gpu, dask-gpu). The 7-PR plan in #1984 called for "one fixture per backend" coverage; previously only the eager read path was exercised. * Comment ``_CANONICAL_KEYS`` to explain the deliberate omission of ``raster_type`` (the implicit 'area' default is encoded as absence, so the constant cannot express it; the two dedicated raster_type tests handle both branches). * Drop ``AREA_OR_POINT: 'Area'`` from the shared ``_GDAL_META`` fixture so the point-branch test does not inherit an inconsistent GDAL_METADATA entry. * Relax the crs_wkt substring check to a regex covering 'WGS 84', 'WGS_1984', and 'WGS-84' so the assertion survives PROJ-version variation across CI platforms. * Note in a comment that ``gdal_metadata['TIFFTAG_SOFTWARE']`` and the raw Software TIFF tag (305) in ``extra_tags`` are independent channels the writer does not synchronise.
This was referenced May 18, 2026
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.
PR 3 of 7 on issue #1984.
Stamps
attrs['_xrspatial_geotiff_contract'] = 1on every DataArrayreturned by an xrspatial geotiff read path. Downstream code reads the
marker to learn which attrs-contract revision produced the array;
later PRs in the series will bump the value when the contract changes.
Summary
_ATTRS_CONTRACT_VERSION = 1inxrspatial/geotiff/_attrs.py._populate_attrs_from_geo_info, which is thesingle chokepoint for the eager numpy, dask+numpy, GPU, dask+GPU,
and COG/HTTP read paths.
_backends/vrt.pyfor the two VRTpaths (eager and chunked) that build their attrs dict directly
rather than going through the helper.
Read paths covered
open_geotiff(eager numpy)open_geotiff(chunks=...)/read_geotiff_dask(dask + numpy)open_geotiff(gpu=True)/read_geotiff_gpu(cupy / GPU)open_geotiff(gpu=True, chunks=...)(dask + cupy)_read_to_arrayand theshared helper)
read_vrt(VRT eager)read_vrt(chunks=...)(VRT chunked / dask)Test plan
pytest xrspatial/geotiff/tests/test_attrs_contract_version_1984.py -x -qpytest xrspatial/geotiff/tests -q(pre-existing GPU and fuzzfailures on
origin/mainare unaffected; no test was previouslyasserting on the exact attrs dict so no other test needed updating)