Skip to content

fix: inner and right joins crashed or kept all element rows when nothing matched - #1312

Merged
jan-glx merged 2 commits into
scverse:mainfrom
jan-glx:fix/1226-inner-right-empty-join
Nov 23, 2026
Merged

jan-glx merged 2 commits into
scverse:mainfrom
jan-glx:fix/1226-inner-right-empty-join

Conversation

@jan-glx

@jan-glx jan-glx commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #1226.

#1266 fixed the left join when the element and the table share no instance. The other join types still broke in that case:

  • points with an inner or right join (match_rows="no" or "left"): KeyError: None, because _get_masked_element passed None to .loc for dask frames
  • inner join with match_rows="left": no error, but the element kept all its rows next to a 0-row table
  • inner or right join with match_rows="right": IndexError from .iloc[0] on the empty merge in _match_rows

This is the minimal fix, three changes in relational_query.py:

  • _get_masked_element skips _match_rows when no table row matches
  • for dask frames it falls back to [] when no table row matches, like it already did for shapes
  • _match_rows returns empty indices for an empty merge (the inner join calls it again with the already emptied element)

The docstring of join_spatialelement_table now says what comes back when nothing matches: an empty element or a 0-row table. None is only returned for the side an exclusive join never returns (the table for left_exclusive, the elements for right_exclusive), so the return type depends on how, not on the data.

The new test runs every how × match_rows combination for shapes, points and labels against a table that shares no instance with the element; 9 of the shapes and points cases fail on main. Labels with an inner join are a strict xfail: inner joins don't collect table rows for labels (documented as unsupported), so they return no table instead of a 0-row one.

#1332 removes the special cases this fix adds to.

@codecov

codecov Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.77%. Comparing base (bc1aecc) to head (19aece2).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1312      +/-   ##
==========================================
+ Coverage   91.71%   91.77%   +0.06%     
==========================================
  Files          53       53              
  Lines        8399     8401       +2     
==========================================
+ Hits         7703     7710       +7     
+ Misses        696      691       -5     
Files with missing lines Coverage Δ
src/spatialdata/_core/query/relational_query.py 94.34% <100.00%> (+1.00%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…ing matched

When the element and the table share no instance, three joins broke:
- points with inner/right (match_rows "no"/"left"): KeyError: None, because
  _get_masked_element passed None to .loc for dask frames
- inner with match_rows="left": the element kept all its rows next to a 0-row table
- inner/right with match_rows="right": IndexError from .iloc[0] on the empty
  merge in _match_rows

_get_masked_element now skips _match_rows when no table row matches and falls
back to [] for dask frames like it already did for shapes, and _match_rows
returns empty indices for an empty merge.

The docstring of join_spatialelement_table now says that an empty result is an
empty element or a 0-row table; None is only returned for the side an
exclusive join never returns.

Closes scverse#1226.
@jan-glx
jan-glx force-pushed the fix/1226-inner-right-empty-join branch from accbe4d to e168b5b Compare November 23, 2026 15:27
@jan-glx
jan-glx marked this pull request as ready for review November 23, 2026 16:11
@jan-glx
jan-glx merged commit dc164f7 into scverse:main Nov 23, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Joins crash (IndexError / KeyError: None) when the element and the table share no instance

2 participants