geotiff: extract input validators to _validation.py (#1882)#1892
Merged
Conversation
Step 4 of #1813's multi-PR refactor of __init__.py. Pure code motion; no public API change. Moved into a new xrspatial/geotiff/_validation.py: - _validate_3d_writer_dims: rejects ambiguous (band,y,x) vs (y,x,band) on 3D writer input (#1812). - _validate_dtype_cast: blocks lossy float-to-int casts on read. - _validate_tile_size: positive int + multiple-of-16 for tiled writers (TIFF 6 TileWidth/TileLength requirement, #1767). - _validate_chunks_arg: positive int / 2-tuple of positive ints for every dask read entry point (#1752, #1776). - _validate_tile_size_arg: backwards-compat wrapper for _validate_tile_size. All five are pure leaves over numpy dtypes and Python primitives; only dependencies are np, _BAND_DIM_NAMES from _coords, and _X_DIM_NAMES/_Y_DIM_NAMES from _runtime (#1880). __init__.py re-imports each name so every existing caller resolves unchanged. Net __init__.py change: 4726 -> 4569 lines (-157). _validation.py is 181 lines. Verification: pixel-parity matrix from #1889 (192 cells), runtime identity tests from #1890 (10), and the validator-specific tests (test_size_param_validation_1752.py, test_size_param_validation_gpu_vrt_1776.py, test_tile_size_multiple_of_16_1767.py, test_to_geotiff_3d_dim_validation_1812.py, test_geotiff_band_bool_rejection_1786.py, test_geotiff_planar_strip_truncation_1782.py) all pass (302/302 green, 1 pre-existing main failure unrelated to this PR). Refs #1813.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extracts GeoTIFF input validation helpers from xrspatial/geotiff/__init__.py into a new shared _validation.py module as part of the ongoing GeoTIFF refactor, while re-importing the validators to preserve existing private import paths.
Changes:
- Adds
xrspatial/geotiff/_validation.pycontaining the moved validator helpers. - Re-imports the validators from
__init__.py. - Removes the validator implementations from
__init__.py.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
xrspatial/geotiff/_validation.py |
New module containing shared GeoTIFF validation helpers. |
xrspatial/geotiff/__init__.py |
Re-imports validators from _validation.py and removes their inline definitions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| _validate_3d_writer_dims, | ||
| _validate_chunks_arg, | ||
| _validate_dtype_cast, | ||
| _validate_tile_size, |
Drop three unused re-imports from __init__.py that Copilot flagged as F401 candidates: - ``_X_DIM_NAMES`` and ``_Y_DIM_NAMES`` from ``._runtime`` — these were only used by ``_validate_3d_writer_dims``, which moved to ``_validation.py`` in this PR. They are no longer needed at the package root. - ``_validate_tile_size`` from ``._validation`` — every internal caller goes through the ``_validate_tile_size_arg`` wrapper, so the bare helper does not need a re-export. The sentinels and helpers that ARE used inside __init__.py (the four SENTINELs, ``_geotiff_strict_mode``, ``_gpu_fallback_warning_message``, ``GeoTIFFFallbackWarning``, the four validators called by entry-point bodies) stay imported. Also drop ``test_dim_name_tuples_are_singleton`` from test_runtime_sentinels_identity_1880.py: the dim-name tuples are not re-exported through ``xrspatial.geotiff`` any more, so there is no identity contract to pin at the package root. The other 9 identity tests stay; they cover the sentinels and helpers that are still re-exported.
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
Step 4 of #1813's multi-PR refactor of
xrspatial/geotiff/__init__.py. Pure code motion; no public API change.Moved into a new
xrspatial/geotiff/_validation.py:_validate_3d_writer_dims— rejects ambiguous(band, y, x)vs(y, x, band)on 3D writer input (to_geotiff: silent data corruption on 3D input with non-whitelisted leading dim #1812)._validate_dtype_cast— blocks lossy float-to-int casts on read._validate_tile_size— positive int + multiple-of-16 for tiled writers (TIFF 6TileWidth/TileLengthrequirement, to_geotiff accepts tile_size values that are not multiples of 16 #1767)._validate_chunks_arg— positive int / 2-tuple of positive ints for every dask read entry point (geotiff: validate tile_size and dask chunks at entry points #1752, geotiff: extend #1752 size-arg validation to write_geotiff_gpu, read_geotiff_gpu, read_vrt #1776)._validate_tile_size_arg— backwards-compat wrapper for_validate_tile_size.All five are pure leaves over numpy dtypes and Python primitives. Only dependencies are
np,_BAND_DIM_NAMESfrom_coords, and_X_DIM_NAMES/_Y_DIM_NAMESfrom_runtime(#1890).__init__.pyre-imports each name so every existing caller resolves unchanged.Diff stats
__init__.py: 4726 → 4569 (-157 lines)._validation.py: 181 lines.Test plan
test_size_param_validation_1752.py,test_size_param_validation_gpu_vrt_1776.pytest_tile_size_multiple_of_16_1767.pytest_to_geotiff_3d_dim_validation_1812.pytest_geotiff_band_bool_rejection_1786.pytest_geotiff_planar_strip_truncation_1782.pytest_size_param_validation_gpu_vrt_1776.py::test_tile_size_positive_worksreproduces on main and is unrelated to this change.from xrspatial.geotiff import _validate_chunks_arg(and the four siblings) — re-export works.Closes #1882. Refs #1813.