bounding_box_query on circles ignores the radius (only the centre is tested), polygon_query does not
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
A circle centred at (11, 5) with radius 3 (disk spans x in [8, 14]) is dropped by bounding_box_query([0,10]×[0,10]) but returned by polygon_query(box(0, 0, 10, 10)), which buffers circles via to_polygons first.
Severity (agent's assessment): medium — the two query APIs disagree for the same rectangle; tables filtered with filter_table=True then differ too
Where: src/spatialdata/_core/query/spatial_query.py, GeoDataFrame overload of bounding_box_query (polygons.sindex.query(bounding_box, predicate="intersects") on the point geometries)
Expected behaviour
Consistent semantics between the two functions (either both consider the disk, or both the centre, documented).
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",
# ]
# ///
"""bounding_box_query on circles only tests the centre; polygon_query with the same box also considers the radius."""
import warnings
import geopandas as gpd
from shapely.geometry import Point, box
from spatialdata import bounding_box_query, polygon_query
from spatialdata.models import ShapesModel
warnings.simplefilter("ignore")
circles = ShapesModel.parse(gpd.GeoDataFrame({"geometry": [Point(11, 5)], "radius": [3.0]})) # disk spans x in [8, 14]
bb = bounding_box_query(circles, axes=("x", "y"), min_coordinate=[0, 0], max_coordinate=[10, 10], target_coordinate_system="global")
pq = polygon_query(circles, polygon=box(0, 0, 10, 10), target_coordinate_system="global")
print("bounding_box_query([0,10]x[0,10]) ->", 0 if bb is None else len(bb), "circles")
print("polygon_query(box(0,0,10,10)) ->", 0 if pq is None else len(pq), "circles")
bug = (bb is None or len(bb) == 0) and pq is not None and len(pq) == 1
print("VERDICT:", "BUG REPRODUCED (inconsistent results)" if bug else "NOT REPRODUCED")
Observed output
bounding_box_query([0,10]x[0,10]) -> 0 circles
polygon_query(box(0,0,10,10)) -> 1 circles
VERDICT: BUG REPRODUCED (inconsistent results)
Possible fix direction (unverified)
Buffer circles before the spatial-index query (as polygon_query does), or document the centre-based behaviour and align polygon_query. Related: #693 (extent and radius).
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
#693
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 by reading the GeoDataFrame overload of bounding_box_query in src/spatialdata/_core/query/spatial_query.py and run the provided repro.py with uv. Check related issue #693 and confirm the intended circle-radius semantics; done means bounding_box_query and polygon_query produce consistent results for the reproduced case, with regression coverage added.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100