Skip to content

resample(): empty rasters not cleanly rejected on scale_factor path #2661

@brendancol

Description

@brendancol

Describe the bug

resample() does not cleanly reject empty rasters on the scale_factor path. _validate_raster() checks dimensionality and numeric dtype, but not for zero-sized spatial axes. When a raster with a zero-length spatial axis (0 rows or 0 columns) is passed with scale_factor, the call reaches coordinate indexing and surfaces an IndexError instead of a clear ValueError.

The target_resolution path already guards against this with a check requiring at least 2 pixels per dimension, but the scale_factor path has no equivalent guard.

The existing coverage test (TestEmptyRasterRejected in test_resample_coverage_2026_05_27.py) currently accepts either IndexError or ValueError, so the contract is acknowledged but not watertight.

Expected behavior

A public function should raise a clear ValueError up front, before reaching coordinate indexing, when handed a raster with a zero-sized spatial axis.

Fix

Extend _validate_raster() (or the scale_factor path) to detect zero-sized spatial axes and raise a clear ValueError, then tighten the coverage test to expect ValueError specifically.

Additional context

Found during a code review of the resample input-validation path.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinginput-validationInput validation and error messages

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions