Repository navigation
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 the spatialdata code base. It has not been verified or triaged by a human yet; the needs: triage label 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
Circle centre (10, 10), radius 1, Scale([4, 1]): true extent x=(36, 44), y=(9, 11); get_extent(exact=True) gives x=(37.5, 42.5), y=(7.5, 12.5); get_extent(exact=False) gives the correct result.
Severity (agent's assessment): medium — the default 'exact' extent of circles is off in both axes under a non-isotropic affine
Where: src/spatialdata/_core/data_extent.py (exact=True branch → transform(e) → scale_radii() scales the radius by the mean of the eigenvalue moduli; _get_extent_of_circles then treats it as a circle)
Expected behaviour
The default path returns the true bounding box.
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",
# ]
# ///
"""get_extent(circles, exact=True) (default) is wrong for anisotropic transformations; exact=False is right."""
import warnings
import geopandas as gpd
from shapely.geometry import Point
from spatialdata import get_extent, to_polygons, transform
from spatialdata.models import ShapesModel
from spatialdata.transformations import Scale
warnings.simplefilter("ignore")
circles = ShapesModel.parse(gpd.GeoDataFrame({"geometry": [Point(10, 10)], "radius": [1.0]}), transformations={"global": Scale([4.0, 1.0], axes=("x", "y"))})
truth = transform(to_polygons(circles, buffer_resolution=64), to_coordinate_system="global").total_bounds
e_exact = get_extent(circles, exact=True)
e_approx = get_extent(circles, exact=False)
print(f"true extent (buffered polygon, transformed): x=({truth[0]:.2f}, {truth[2]:.2f}) y=({truth[1]:.2f}, {truth[3]:.2f})")
print("get_extent exact=True :", {k: tuple(round(float(x), 2) for x in v) for k, v in e_exact.items()})
print("get_extent exact=False:", {k: tuple(round(float(x), 2) for x in v) for k, v in e_approx.items()})
bug = abs(e_exact["x"][0] - truth[0]) > 0.1 or abs(e_exact["y"][1] - truth[3]) > 0.1
print("VERDICT:", "BUG REPRODUCED" if bug else "NOT REPRODUCED")Observed output
true extent (buffered polygon, transformed): x=(36.00, 44.00) y=(9.00, 11.00)
get_extent exact=True : {'x': (37.5, 42.5), 'y': (7.5, 12.5)}
get_extent exact=False: {'x': (36.0, 44.0), 'y': (9.0, 11.0)}
VERDICT: BUG REPRODUCED
Possible fix direction (unverified)
For circles in the exact=True branch compute the extent from the intrinsic circle bounds transformed to the target coordinate system (what exact=False does), or buffer to polygons before transforming when the transformation is not a similarity (scale_radii already detects anisotropy).
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.
Possibly related issues
Automatically generated; discovered by an AI agent (Claude) and not yet reviewed by a human.
Activity