Skip to content

geotiff: extract input validators to _validation.py (#1882)#1892

Merged
brendancol merged 2 commits into
mainfrom
issue-1882
May 15, 2026
Merged

geotiff: extract input validators to _validation.py (#1882)#1892
brendancol merged 2 commits into
mainfrom
issue-1882

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

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:

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 (#1890). __init__.py re-imports each name so every existing caller resolves unchanged.

Diff stats

  • __init__.py: 4726 → 4569 (-157 lines).
  • New _validation.py: 181 lines.

Test plan

  • Pixel-byte-parity matrix from geotiff: add end-to-end pixel-byte-parity test matrix (#1879) #1889 — 192/192 pass.
  • Runtime-sentinel identity tests from geotiff: extract sentinels, fallback warning, strict-mode helper to _runtime.py (#1880) #1890 — 10/10 pass.
  • Validator-specific tests through the public surface — all pass:
    • 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
  • 302/302 of the tests run here pass; the 1 failure in test_size_param_validation_gpu_vrt_1776.py::test_tile_size_positive_works reproduces 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.

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.
@github-actions github-actions Bot added the performance PR touches performance-sensitive code label May 15, 2026
@brendancol brendancol requested a review from Copilot May 15, 2026 03:07
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 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.py containing 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.

Comment thread xrspatial/geotiff/__init__.py Outdated
_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.
@brendancol brendancol merged commit a1be197 into main May 15, 2026
10 of 11 checks passed
@brendancol brendancol deleted the issue-1882 branch May 15, 2026 04:40
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: extract input validators into _validation.py (#1813 step 4)

2 participants