Skip to content

docs: queries return MultiPolygons whole - #1265

Merged
LucaMarconato merged 2 commits into
scverse:mainfrom
FarisHrvat:doc-multipolygon-query
Nov 11, 2026
Merged

LucaMarconato merged 2 commits into
scverse:mainfrom
FarisHrvat:doc-multipolygon-query

Conversation

@FarisHrvat

Copy link
Copy Markdown
Contributor

Fixes #1255

Documents that bounding_box_query and polygon_query without clip return shapes whole, including MultiPolygon components entirely outside the query region, and points to polygon_query(clip=True) with shapely.box(...) for cutting them.

bounding_box_query and polygon_query without clip keep every component of a
MultiPolygon that intersects the query region, including components entirely
outside of it. Say so, and point to polygon_query(clip=True).

Fixes scverse#1255
@codecov

codecov Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.43%. Comparing base (bd410fa) to head (7f0f9b0).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1265   +/-   ##
=======================================
  Coverage   91.43%   91.43%           
=======================================
  Files          53       53           
  Lines        8395     8395           
=======================================
  Hits         7676     7676           
  Misses        719      719           
Files with missing lines Coverage Δ
src/spatialdata/_core/query/spatial_query.py 95.01% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@LucaMarconato LucaMarconato left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

LucaMarconato pushed a commit that referenced this pull request Nov 11, 2026
Querying a labels element that is annotated by a table, but whose
cropped area contains none of the annotated instances, crashes
`polygon_query` and `bounding_box_query` with `IndexError: list index
out of range` in `_region_as_str_if_list_of_len_one`, which reads the
first element of an empty region list.

The helper now only unwraps a list of length one. A left join with no
matching rows returns an empty table with `region == []`, as the
docstring and the storage format spec describe, and the query callers
already drop empty tables, so the query keeps the labels and drops the
table. The exclusive and right joins use the same helper, so they're
covered too. Thanks to @jan-glx for the suggestion.

It's also the random failure of `test_attributes_are_copied[labels2d-*]`
in the pre-release job on #1265. The labels there come from the shared
`RNG` in `conftest.py`, so whether the small query box contains an
annotated instance depends on which tests ran before on the same worker.
Added a test that builds that case on purpose.

Also addresses the left join part of #1226.

---------

Co-authored-by: Jan Gleixner <jan.gleixner+git@gmail.com>
@LucaMarconato
LucaMarconato enabled auto-merge (squash) November 11, 2026 12:26
@LucaMarconato
LucaMarconato merged commit 81a5959 into scverse:main Nov 11, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Document that spatial queries on MultiPolygon keep also the components outside the queried region

2 participants