Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug join operation with non-annotating table #864

Merged
merged 1 commit into from
Feb 6, 2025

Conversation

LucaMarconato
Copy link
Member

This PR is very small (I modified only src/spatialdata/_core/query/relational_query.py, the rest is from the new ruff pre-commit).

This PR fixes a subtle bug that originated when all the following occurred simultaneously:

  1. we did join operation between an element, and a table that is not annotating the element
  2. instead the table is annotating 1 (not 2 or more) other elements
  3. the name of the element being annotated is a string that contains the name of the element we are joining against

This occurred for instance with this code:

from spatialdata_io import visium_hd
from pathlib import Path
from napari_spatialdata import Interactive

path = Path("../../spatialdata-sandbox/visium_hd_3.1.1_io")
assert path.exists()

path_read = path / "data"
path_write = path / "data.zarr"

sdata = visium_hd(path_read, load_all_images=True, annotate_table_by_labels=True, bin_size=[16])

interactive = Interactive(sdata, headless=True)
interactive.add_element("Visium_HD_Human_Lung_Cancer_Fixed_Frozen_square_016um", "global")
interactive.run()

This occurred because in the cases above region was a str, not a list[str], and therefore, in the screenshot below,
image
the check in the highlighted line, which should fail (because the table is not annotating the element), instead succeeds (because name is a substring of regions).
But name is not a valid group of groups_df, which leads to a KeyError.

Solution

The solution is very simple. Still, two observations (CC @melonora):

Copy link

codecov bot commented Feb 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.96%. Comparing base (e3ab814) to head (bd24238).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #864      +/-   ##
==========================================
+ Coverage   91.95%   91.96%   +0.01%     
==========================================
  Files          47       47              
  Lines        7345     7355      +10     
==========================================
+ Hits         6754     6764      +10     
  Misses        591      591              
Files with missing lines Coverage Δ
src/spatialdata/_core/query/relational_query.py 90.98% <100.00%> (+0.20%) ⬆️

@LucaMarconato LucaMarconato merged commit c2136b3 into main Feb 6, 2025
7 checks passed
@LucaMarconato LucaMarconato deleted the fix/bug-region-join branch February 6, 2025 23:55
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.

1 participant