Repository navigation
Conversation
When pp.neighbors runs with its own n_pcs=None default, it uses every stored PCA component unsliced (_get_pca_or_small_x). Ingest's fallback branch for "no use_rep/n_pcs recorded" instead hardcoded settings.N_PCS (50), silently using a different, truncated representation than the one that actually produced the reference neighbor graph whenever more than 50 PCs were computed (e.g. sc.pp.pca(adata, n_comps=100) followed by sc.pp.neighbors(adata)). Fixes it by using the full stored X_pca, matching pp.neighbors' actual default behavior instead of assuming it always caps at settings.N_PCS.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4401 +/- ##
=======================================
Coverage 83.78% 83.78%
=======================================
Files 134 134
Lines 12691 12691
=======================================
Hits 10633 10633
Misses 2058 2058
Flags with carried forward coverage won't be shown. Click here to find out more.
|
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.
Ingestfalls back to a hardcodedsettings.N_PCS(50) whenever the referenceadata'sneighborsparams recorded neitheruse_repnorn_pcs— but that's exactly the statepp.neighborsleaves when called with its own defaults, and its default (n_pcs=None) uses the full stored PCA representation unsliced (_get_pca_or_small_x), not 50 components. Whenever more than 50 PCs were computed (e.g.sc.pp.pca(adata, n_comps=100)thensc.pp.neighbors(adata)),Ingestsilently builds its KNN index and transforms new data in a different, truncated representation than the one that actually produced the reference neighbor graph — no error, just a quietly wrong embedding/label mapping forsc.tl.ingest.Found via sibling comparison between
Ingest._init_neighbors's three branches and_get_pca_or_small_x(the function that actually computespp.neighbors' representation) — the first two branches already match the stored params correctly; only the fallback diverged.Repro
AI assistance
Ingest's three_init_neighborsbranches against_get_pca_or_small_x's actual default behavior, then wrote the fix and regression testpbmc68k_reducedtest fixture hits an unrelated zarr-version incompatibility in this environment, so the new test couldn't be run through the full suite here — logic was verified directly against the samesc.pp.pca/sc.pp.neighbors/sc.tl.Ingestcalls the test uses)Test results
Added
test_representation_more_than_n_pcs_defaulttotests/test_ingest.py, coveringn_comps = settings.N_PCS + 20. Manually verified the underlying fix acrossn_compsof 30, 50, and 100 against a syntheticAnnData(below, below+at, and above thesettings.N_PCSthreshold) — all three now correctly match the PCspp.neighborsactually used, whereas 100 previously and incorrectly truncated to 50.