scverse / scverse/spatialdata-plot
render_labels raises IndexError when the table has rows for instances absent from the mask
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 86
- Fork
- 21
- Merge trung bình
- 14 giờ 50 phút
- Pull request đã merge (30 ngày)
- 3
Mô tả
A table may annotate instances that no longer exist in the labels element — e.g. objects lost when segmentation is regenerated, or a table read from an upstream pipeline. render_labels(color=...) then fails instead of treating them as missing.
import anndata as ad, numpy as np, pandas as pd, spatialdata as sd, spatialdata_plot # noqa
from spatialdata.models import Labels2DModel, TableModel
labels = np.zeros((16, 16), np.uint32)
labels[2:6, 2:6] = 1
labels[8:12, 8:12] = 2
obs = pd.DataFrame({"instance_id": [1, 2, 3], "region": pd.Categorical(["labels"] * 3)})
obs.index = obs.index.astype(str)
table = TableModel.parse(
ad.AnnData(np.zeros((3, 1), np.float32), obs=obs),
region="labels", region_key="region", instance_key="instance_id",
)
table.obs["value"] = [1.0, 2.0, 3.0]
sdata = sd.SpatialData(
labels={"labels": Labels2DModel.parse(labels, dims=("y", "x"))},
tables={"table": table},
)
sdata.pl.render_labels("labels", color="value", table_name="table").pl.show()
IndexError: boolean index did not match indexed array along axis 0;
size of axis is 2 but size of corresponding boolean axis is 3
The mask is computed from the instance ids present in the labels, but ColorSpec.source_vector/color_vector still have one entry per table row, so ColorSpec.filter indexes a length-2 array with a length-3 mask:
spatialdata_plot/pl/render.py:2409 → spatialdata_plot/pl/_color.py:791
Rendering without color works, as does dropping the unmatched rows from the table.
spatialdata 0.8.0, spatialdata-plot 0.4.2, Python 3.14.
Hướng dẫn đóng góp
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.
Hướng nghiên cứu
Chạy bản tái hiện Python được cung cấp, sau đó kiểm tra spatialdata_plot/pl/render.py quanh dòng 2409 và spatialdata_plot/pl/_color.py quanh dòng 791. Theo dõi cách mask labels và các vector ColorSpec được lọc; hoàn thành khi render_labels(color=...) xử lý các hàng trong bảng không có trong labels mà không gây ra IndexError, đồng thời giữ nguyên hành vi hiện tại đối với các hàng khớp.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- numpy, pandas, python
- Lĩnh vực
- data-visualization
- Loại issue
- Lỗi
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức độ hoạt động
- Sôi nổi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 84/100