Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/spatialdata_plot/pl/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ def _render_shapes(
outline_color_vector: Any = None
if col_for_outline_color is not None:
# When the outline column lives in a table that hasn't been joined yet
# (no fill table, or a different table than fill's), inner-join it onto
# (no fill table, or a different table than fill's), left-join it onto
# the element so the lookup is aligned and the element row count matches
# the outline vector length.
if outline_table_name is not None and outline_table_name != table_name:
Expand Down
8 changes: 6 additions & 2 deletions src/spatialdata_plot/pl/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,11 @@ def _join_table_for_element(
element: str,
table_name: str,
) -> tuple[Any, AnnData]:
"""Inner-join ``element`` with its annotating ``table_name``.
"""Left-join ``element`` with its annotating ``table_name``.

A left join keeps every shape, including those without a table row (they get no color value and
are rendered with ``na_color``), matching the points/labels behaviour instead of silently dropping
unannotated shapes.

Wraps the workaround for scverse/spatialdata#1099: ``join_spatialelement_table``
calls ``table.obs.reset_index()`` which fails when the obs index name matches
Expand All @@ -470,7 +474,7 @@ def _join_table_for_element(

try:
element_dict, joined_table = join_spatialelement_table(
sdata, spatial_element_names=element, table_name=table_name, how="inner"
sdata, spatial_element_names=element, table_name=table_name, how="left"
)
finally:
if _saved_index is not None:
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/_images/Shapes_can_do_non_matching_table.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/_images/Shapes_fill_and_outline_both_obs_columns.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/_images/Shapes_respects_custom_colors_from_uns.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions tests/pl/test_render_shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,20 @@ def test_render_shapes_raises_for_missing_column_in_table(self, sdata_blobs_shap
element="blobs_polygons", color="not_a_column", table_name="table"
)

def test_plot_shapes_unannotated_by_table_render_with_na_color(self, sdata_blobs_shapes_annotated: SpatialData):
# Regression for #710: blobs_polygons instance 0 has no row in the table (instance_id starts
# at 1), so coloring by a table column must render it with na_color, not drop it.
sdata_blobs_shapes_annotated.pl.render_shapes(
"blobs_polygons", color="channel_0_sum", na_color="red"
).pl.show()

def test_plot_shapes_unannotated_by_table_hidden_with_na_color_none(self, sdata_blobs_shapes_annotated: SpatialData):
# Counterpart to the test above: na_color=None makes the unannotated polygon (instance 0)
# transparent, opting back into hiding it.
sdata_blobs_shapes_annotated.pl.render_shapes(
"blobs_polygons", color="channel_0_sum", na_color=None
).pl.show()

def test_plot_can_plot_shapes_after_spatial_query(self, sdata_blobs: SpatialData):
# subset to only shapes, should be unnecessary after rasterizeation of multiscale images is included
blob = SpatialData.init_from_elements(
Expand Down
Loading