bounding_box_query on circles ignores the radius (only the centre is tested), polygon_query does not

Aperta
#1,232 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
python
Ambito
data

Direzione di ricerca

Inizia leggendo l’overload GeoDataFrame di bounding_box_query in src/spatialdata/_core/query/spatial_query.py ed esegui repro.py con uv. Controlla l’issue correlata #693 e conferma la semantica prevista del raggio del cerchio; il lavoro è completato quando bounding_box_query e polygon_query producono risultati coerenti per il caso riprodotto e viene aggiunta la copertura di regressione.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug 🚨 element: shapes ▲ method: query needs: triage priority: medium

[!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

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.

Lingua principale
Python
Stelle
394
Fork
95
Merge medio
3g 9h
PR unite (30g)
5

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di scverse/spatialdata

Tutte le issue di scverse/spatialdata

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.