Repository navigation
Conversation
added 2 commits
November 7, 2026 21:24
…m adata When fold changes or fractions are recomputed, gene positions come from `var_names.get_indexer`, which returns -1 for names that are not present. `x[:, -1]` then silently scores those genes with the values of the last gene in `adata`, so removed genes can pass the filter. Raise a KeyError naming the missing genes instead, and skip NaN names so an already filtered result can still be filtered again. Fixes scverse#1487
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4497 +/- ##
=======================================
Coverage 85.13% 85.14%
=======================================
Files 138 138
Lines 12247 12253 +6
=======================================
+ Hits 10427 10433 +6
Misses 1820 1820
Flags with carried forward coverage won't be shown. Click here to find out more.
|
| def test_filter_rank_genes_groups_refilter() -> None: | ||
| """Filtering an already filtered result (with NaN names) still works.""" | ||
| adata = pbmc68k_reduced() | ||
| rank_genes_groups(adata, "bulk_labels", method="wilcoxon", n_genes=5) |
There was a problem hiding this comment.
Could this refilter test also cover pts=True? With cached pts/pts_rest, the first filter leaves NaNs in names, and a second filter_rank_genes_groups(key='rank_genes_groups_filtered') calls .loc[var_names] with those NaNs, raising KeyError. The new helper skips NaNs for matrix indexing, but the cached-fraction path still needs the same handling.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When
filter_rank_genes_groupsrecomputes fold changes or fractions (for example with a differentuse_raw, layer orgroupbythanrank_genes_groups), gene positions come fromvar_names.get_indexer, which returns -1 for names that are not present.x[:, -1]then silently scores those genes with the values of the last gene inadata, so genes that were removed can still pass the filter.The original
KeyErrorfrom #1487 no longer occurs onmain, but the same situation now gives wrong results without any error.Reproduction on current
mainChange
_get_var_idx, which raises aKeyErrornaming the missing genes, theunskey and the group, and suggests rerunningrank_genes_groupsor passing the sameuse_raw/use.key="rank_genes_groups_filtered") can still be filtered again.ptsandlogfoldchangesare reused from the stored results, behavior is unchanged.I chose to raise rather than treat missing genes as filtered, since that would hide a likely mistake (for example ranking on
.rawand filtering an HVG subset). Happy to switch to a warning plus NaN if you prefer.Tests
test_filter_rank_genes_groups_missing_genes: fails onmain, passes with this change.test_filter_rank_genes_groups_refilter: filtering a filtered result still works.tests/test_rank_genes_groups.py,tests/test_filter_rank_genes_groups.py,tests/test_queries.pyand thefilter_rank_genes_groupsplotting test pass locally;ruff checkandruff formatare clean.LLM usage
LLM or coding agent used: Claude Opus 5.5 via Claude Code
If one was used, I, a human, have reviewed, understood and tested every changed line
Closes f"Values {list(not_found)}, from {list(indexer)}, " "are not valid obs/ var names or indices." #1487
Tests included or not required because:
Release notes not necessary because: