unpad_raster() (public API) raises 'Please report this bug' on any all-zero raster
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 394
- Forks
- 95
- Avg merge
- 4d 3h
- Merged PRs (30d)
- 7
Description
[!NOTE]
This whole message is AI-generated. The issue was automatically discovered and reported by an AI agent (Claude) during an autonomous bug hunt on thespatialdatacode base. It has not been verified or triaged by a human yet; theneeds: triagelabel is set so that a maintainer can confirm it. The reproduction script below was executed by the agent in an isolated environment (see Environment) and its output is pasted verbatim.
Summary
unpad_raster(Image2DModel.parse(np.zeros((1, 5, 5)))) → ValueError: Expected maximum coordinate for axis y to be4,but got 4.5. Please report this bug. (note also the message formatting).
Severity (agent's assessment): low/medium — an all-zero raster (empty mask, blank tile) is a legitimate input
Where: src/spatialdata/_utils.py::unpad_raster._compute_paddings (coordinate checks against 0 and shape-1 while compute_coordinates uses pixel centres 0.5, 1.5, ...; also if not min_coordinate != 0 is inverted)
Expected behaviour
The raster is returned unchanged (nothing to unpad).
Reproduction
Save as repro.py and run uv run repro.py (the PEP 723 header pins spatialdata to the commit the bug was found on; replace the URL fragment with @main to test the current main branch).
# /// script
# requires-python = ">=3.12"
# dependencies = [
# "spatialdata @ git+https://github.com/scverse/spatialdata.git@ccf1ea048d054b6624214bf618008a9f9ae223e0",
# ]
# ///
"""unpad_raster() raises 'Please report this bug' on any all-zero raster."""
import warnings
import numpy as np
from spatialdata import unpad_raster
from spatialdata.models import Image2DModel, Labels2DModel
warnings.simplefilter("ignore")
bug = False
for name, el in [("all-zero image", Image2DModel.parse(np.zeros((1, 5, 5)))), ("all-zero labels", Labels2DModel.parse(np.zeros((5, 5), dtype=np.uint8))), ("non-zero image (control)", Image2DModel.parse(np.ones((1, 5, 5))))]:
try:
out = unpad_raster(el)
print(f"{name:25s}: OK, shape {out.shape}")
except Exception as e: # noqa: BLE001
print(f"{name:25s}: {type(e).__name__}: {e}")
bug = True
print("VERDICT:", "BUG REPRODUCED" if bug else "NOT REPRODUCED")
Observed output
all-zero image : ValueError: Expected maximum coordinate for axis y to be4,but got 4.5. Please report this bug.
all-zero labels : ValueError: Expected maximum coordinate for axis y to be4,but got 4.5. Please report this bug.
non-zero image (control) : OK, shape (1, 5, 5)
VERDICT: BUG REPRODUCED
Possible fix direction (unverified)
Remove the two coordinate assertions (or compare against 0.5 / shape − 0.5) and fix the message.
Environment
uv run repro.py with the PEP 723 metadata in the script (fresh, isolated environment; spatialdata built from main @ ccf1ea0 (2026-08-28); Python 3.13, latest releases of the dependencies at run time: pandas 3.0, anndata 0.13, zarr 3.3, dask 2026.8, numpy 2.5, geopandas 1.1, shapely 2.1). macOS (arm64). Also reproduced in a second environment with pandas 2.3.3 / anndata 0.12.11 / numpy 2.4.4 / zarr 3.2.1.
Automatically generated; discovered by an AI agent (Claude) and not yet reviewed by a human.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/spatialdata/_utils.py at unpad_raster._compute_paddings and run the supplied repro.py with uv. Check the coordinate validation against the pixel-centre coordinates used by compute_coordinates, then verify that all-zero images and labels return unchanged and the non-zero control still succeeds.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100