geotiff: validate tile_size and chunks size args (#1752)#1757
Open
brendancol wants to merge 1 commit into
Open
geotiff: validate tile_size and chunks size args (#1752)#1757brendancol wants to merge 1 commit into
brendancol wants to merge 1 commit into
Conversation
`to_geotiff(..., tiled=True, tile_size=0)` reached the tiled writer where `math.ceil(width / tile_size)` raised `ZeroDivisionError` without naming `tile_size`. `read_geotiff_dask(chunks=0)` (or `chunks=(0, N)`) propagated zero into dask's chunk math and surfaced as a confusing `range()` / empty-chunks error. Add up-front checks at both entry points that reject non-positive ints, non-int values, and malformed `chunks` tuples with a `ValueError` that names the parameter and the bad value. Style matches the existing `window=` validator in `read_geotiff_dask`. Closes #1752.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens the GeoTIFF API surface by validating size-related parameters (tile_size for tiled writes and chunks for dask reads) early, so invalid inputs fail with clear ValueErrors rather than confusing downstream exceptions.
Changes:
- Add up-front
tile_sizevalidation into_geotiffwhentiled=True. - Add up-front
chunksvalidation inread_geotiff_daskfor scalar and(row, col)tuple forms. - Add regression tests covering invalid/valid combinations for both entry points.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
xrspatial/geotiff/__init__.py |
Adds parameter validation for tile_size (tiled writes) and chunks (dask reads) to improve error clarity and prevent downstream failures. |
xrspatial/geotiff/tests/test_size_param_validation_1752.py |
Introduces regression tests ensuring invalid sizes raise ValueError and valid sizes continue to work. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+1929
to
+1935
| # was the problem. ``chunks`` may be an int or a (row, col) tuple. | ||
| if isinstance(chunks, int) and not isinstance(chunks, bool): | ||
| if chunks <= 0: | ||
| raise ValueError( | ||
| f"chunks must be a positive int or (row, col) tuple of " | ||
| f"positive ints, got chunks={chunks}.") | ||
| elif isinstance(chunks, tuple): |
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
to_geotiff(..., tiled=True, tile_size=0)reached the tiled writer wheremath.ceil(width / tile_size)raisedZeroDivisionErrorwith no indication thattile_sizewas the bad input. Negative values produced a nonsensical tile grid.read_geotiff_dask(chunks=0)(orchunks=(0, N)) propagated zero into dask's chunk math and surfaced as a confusingrange()/ empty-chunks error.chunkstuples with aValueErrorthat names the parameter and the bad value.tiled=Falseskips thetile_sizecheck since the writer ignorestile_sizein strip mode.window=validator inread_geotiff_dask.Closes #1752.
Test plan
test_size_param_validation_1752.py(11 tests):tile_size0 / negative / non-int rejected,tile_size=1still writes;chunks0 / negative /(0, N)/(N, -1)/ 3-tuple rejected;chunks=256andchunks=(4, 8)still read.RecursionErrorintest_features.py, GPUtest_predictor2_big_endian_gpu_1517.py, GPUtest_no_georef_windowed_coords_1710.py) reproduce on main without this change.