to_polygons(labels) turns a label containing a hole into an invalid MultiPolygon with the hole counted as area
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 64/100
Hướng nghiên cứu
Bắt đầu với src/spatialdata/_core/operations/vectorize.py::_region_props_to_polygon và chạy repro.py được cung cấp bằng uv. So sánh hình học thu được với Polygon hợp lệ được mong đợi, chứa một vòng bên trong và diện tích 24.0, sau đó thêm một bài kiểm thử hồi quy cho trường hợp vòng được gắn nhãn nếu có thể xác định vị trí kiểm thử trong repository.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
[!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 5×5 label with a 1-pixel hole (true area 24) becomes MultiPolygon, is_valid=False, area 25.0. Inner contours should become interiors of the enclosing polygon.
Severity (agent's assessment): medium — invalid geometries break downstream sjoin/overlay/clip; 24 of 3,556 polygons are invalid on the CosMx sandbox dataset
Where: src/spatialdata/_core/operations/vectorize.py::_region_props_to_polygon (every contour from skimage.measure.find_contours becomes an independent Polygon wrapped in a MultiPolygon)
Expected behaviour
A valid Polygon with one interior ring and area 24.
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",
# ]
# ///
"""to_polygons(labels) turns a label with a hole into an invalid MultiPolygon whose area includes the hole."""
import warnings
import numpy as np
from spatialdata import to_polygons
from spatialdata.models import Labels2DModel
warnings.simplefilter("ignore")
arr = np.zeros((7, 7), dtype=np.uint16)
arr[1:6, 1:6] = 1
arr[3, 3] = 0 # 5x5 square with a one-pixel hole -> true area 24
polys = to_polygons(Labels2DModel.parse(arr))
g = polys.geometry.iloc[0]
print(f"geometry type={g.geom_type}, is_valid={g.is_valid}, area={g.area} (expected: valid Polygon with one interior, area 24.0)")
bug = (not g.is_valid) or abs(g.area - 24.0) > 1e-9
print("VERDICT:", "BUG REPRODUCED" if bug else "NOT REPRODUCED")
Observed output
geometry type=MultiPolygon, is_valid=False, area=25.0 (expected: valid Polygon with one interior, area 24.0)
VERDICT: BUG REPRODUCED
Possible fix direction (unverified)
Build polygons with shapely.polygonize/build_area from the contour rings, or classify contours by containment (Polygon(outer, holes=[...])); add make_valid() as a safety net and a test with a labelled ring.
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.
- Ngôn ngữ chính
- Python
- Star
- 394
- Fork
- 95
- Merge trung bình
- 3 ngày 9 giờ
- Pull request đã merge (30 ngày)
- 5
Chuẩn bị môi trường
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của scverse/spatialdata
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
scverse/spatialdata#1256 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug 🚨 element: labels 🏷️ method: aggregation 🔢 needs: triage priority: medium
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
scverse/spatialdata#1249 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug 🚨 element: images 🌌 element: labels 🏷️ needs: triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
scverse/spatialdata#1239 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug 🚨 element: shapes ▲ models needs: triage priority: medium
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
scverse/spatialdata#1234 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug 🚨 element: labels 🏷️ method: aggregation 🔢 needs: triage priority: medium
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
scverse/spatialdata#1230 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của scverse/spatialdata
Issue tương tự
-
Broken links found in docsĐang mởdocs pydanty:is-working
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
pydantic/pydantic-ai#8863 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
run-llama/llama_index#23278 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
documentation from-review-extraction github-actions priority: low severity:nit
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
LearningCircuit/local-deep-research#6946 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
oracle/langchain-oracle#323 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
tenstorrent/tt-metal#58057 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày