Skip to content

bump: validate agg, count, and spread inputs#3614

Open
brendancol wants to merge 1 commit into
xarray-contrib:mainfrom
brendancol:deep-sweep-error-handling-bump-2026-07-02
Open

bump: validate agg, count, and spread inputs#3614
brendancol wants to merge 1 commit into
xarray-contrib:mainfrom
brendancol:deep-sweep-error-handling-bump-2026-07-02

Conversation

@brendancol

@brendancol brendancol commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

What

bump() validated only width and height. This adds the same style of validation to agg, count, and spread, using the existing _validate_raster and _validate_scalar helpers.

Before, bad inputs surfaced errors from deep in the call or passed silently:

input old behavior
agg=np.zeros((10,10)) TypeError: Unsupported Array Type from the backend dispatcher
agg 3D/1D DataArray ValueError: too many values to unpack from h, w = agg.shape
count=-5 / count=5.0 raw np.empty errors
spread=-3 / spread=2.5 accepted silently, no spreading applied

After, each raises a message that names the parameter, e.g. bump(): \agg` must be 2D, got 3D`.

Notes

  • bump only reads agg's shape and backend, so I left the dtype unchecked (numeric=False).
  • spread=0 and count=0 stay valid.
  • Rejecting negative/non-int spread changes behavior for inputs that were previously accepted silently. Those values are out of domain per the docstring (spread : int), and no test relied on them.

Tests

Added error-path tests asserting the new exception type and message for each case, plus a check that spread=0 still works. Full test_bump.py passes (23 tests) on numpy, cupy, dask, and dask+cupy.


error-handling sweep, 2026-07-02

bump() only validated width and height. Bad values for the agg template,
count, and spread surfaced numpy/dispatcher errors from deep in the call
or were silently accepted:

- agg as a plain ndarray -> 'Unsupported Array Type' from the backend
  dispatcher; a 3D/1D DataArray -> 'too many values to unpack' from the
  bare h, w = agg.shape unpack. Neither named agg.
- count negative/float -> raw np.empty errors.
- spread negative/float -> accepted silently, dropping the spreading the
  caller asked for despite the docstring saying int.

Add _validate_raster(agg, ndim=2, numeric=False) and _validate_scalar for
count (>=0) and spread (>=0), matching the existing width/height checks.
bump only reads agg's shape/backend so dtype stays unchecked. spread=0 and
count=0 remain valid. Verified across numpy, cupy, dask, and dask+cupy.

error-handling sweep 2026-07-02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant