Skip to content

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

Draft
jan-glx wants to merge 1 commit into
scverse:mainfrom
jan-glx:fix/1226-inner-right-empty-join
Draft

jan-glx wants to merge 1 commit 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

_get_masked_element now uses an empty array instead of None when nothing matches, so the existing ordering code and .loc handle that case for shapes and points alike. _match_rows returns empty indices for an empty merge.

The new test runs every how × match_rows combination for shapes and points against a table that shares no instance with the element; 9 of the 30 cases fail on main. The results now match the docstring of join_spatialelement_table: left keeps the element and returns a 0-row table, inner returns an empty element and a 0-row table, right returns an empty element and the full table.

…ing matched

With no instance shared between the element and the table, `_get_masked_element`
passed `None` to `.loc` for points (KeyError: None), kept every element row for
`match_rows="left"`, and `_match_rows` read `.iloc[0]` of an empty merge for
`match_rows="right"` (IndexError). Return an empty element in all three cases.

Closes scverse#1226
@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.43%. Comparing base (602aec0) to head (d7dbad6).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1312   +/-   ##
=======================================
  Coverage   91.43%   91.43%           
=======================================
  Files          53       53           
  Lines        8395     8395           
=======================================
  Hits         7676     7676           
  Misses        719      719           
Files with missing lines Coverage Δ
src/spatialdata/_core/query/relational_query.py 93.34% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

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

1 participant