Skip to content

Restore Pandas membership checks for string instance IDs - #1280

Open
sophiamaedler wants to merge 2 commits into
scverse:mainfrom
sophiamaedler:pandas_filter
Open

sophiamaedler wants to merge 2 commits into
scverse:mainfrom
sophiamaedler:pandas_filter

Conversation

@sophiamaedler

Copy link
Copy Markdown

Closes #1279.

_get_joined_table_indices and _get_masked_element use NumPy isin to match table instance IDs against spatial element indices. For object or string IDs, this can trigger repeated element-wise comparisons and make bounding_box_query substantially slower. This PR uses Pandas Series.isin() in both helpers while preserving the existing join behavior.

Benchmark

Using the benchmark script and the public Xenium breast cancer dataset linked in the issue, I ran ten crops per ID type on main and this PR branch. The dataset has 167,780 cells; each crop retained 199 cells. For the string-ID case, the sample’s numeric IDs were cast to strings in memory.

Cell ID type main median PR median Change
Numeric 0.0082 s 0.0096 s Comparable in absolute time
String 0.4126 s 0.0141 s 29× faster

The benchmark script is attached to issue #1279.

@codecov

codecov Bot commented Oct 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.42%. Comparing base (9ffe082) to head (e67602a).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1280   +/-   ##
=======================================
  Coverage   91.42%   91.42%           
=======================================
  Files          53       53           
  Lines        8381     8381           
=======================================
  Hits         7662     7662           
  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.

bounding_box_query slows down with string cell IDs in newest spatialdata release

1 participant