Repository navigation
Use post-filter site count for window filtering in local PCA - #447
Merged
Merged
Conversation
nspope
force-pushed
the
fix/373-local-pca-validity-gate
branch
from
November 20, 2026 04:49
391666b to
6e46d87
Compare
andrewkern
approved these changes
Nov 20, 2026
andrewkern
left a comment
Member
There was a problem hiding this comment.
Checked this against main on all the paths: the three local_pca engines, local_pca_jackknife, lostruct(jackknife=True) and windowed_analysis. The empty-after-exclude window is NaN everywhere now, and the two jackknife gates agree. Notes:
- The same output is still there under
'include'when a window has no usable call: every call missing gives eigvals[0, 0]andsumsq0 on all three engines, because the site count is 10 but there are no one-hot columns. A monomorphic window does the same. Gating on zero columns as well would cover it; fine as a follow-up if you'd rather keep this one to #373. - Needs a rebase; the changelog and the pipeline map moved on
main. - Small: no test for
local_pca_jackknifeor thelostructpath with a window the exclude filter empties. Both behave in my runs.
local_pca (every engine) and local_pca_jackknife decided window validity from window.n_variants, counted before missing_data='exclude' removed incomplete sites, so a window with no complete site looked valid and got degenerate eigvals/sumsq/eigvecs instead of NaN. _local_pca_with_jackknife's jackknife gate also compared against X.shape[1] (one-hot columns), which can exceed the real site count, so it could disagree with local_pca_jackknife on the same window. _centered_block/_prepare_centered now also return the site count left after the exclude filter, and all four window-processing paths re-gate on it instead of the pre-filter or one-hot-column counts. Block splitting inside the jackknife still operates on X's own columns, since that's what's actually indexed.
The real-site-count gate still passed a window whose calls are all missing under missing_data='include' (the exclude filter never runs, so the site count is unchanged), leaving X with zero one-hot columns and producing eigvals of 0, sumsq of 0, and a degenerate PC1 instead of NaN. local_pca (every engine) and _local_pca_with_jackknife now also reject a window whose standardized X has no columns at all. local_pca_jackknife already rejected this case through its block-width gate, so it needed no change.
local_pca already had this case covered for all three engines, and the jackknife paths had it covered for the exclude-filter-empties-it case, but _local_pca_with_jackknife's own zero-one-hot-column branch (the all-missing case under missing_data='include') had no test exercising it. Confirmed it fails against the pre-fix code (eigvals [0, 0]).
Leaving out the one and only block empties every window entirely, but that standardizes to a valid-looking all-zero Gram instead of NaN, so local_pca_jackknife, _local_pca_with_jackknife, and lostruct(jackknife=True) silently returned an SE of 0.0 for n_blocks=1 instead of erroring or giving NaN. Confirmed empirically before the fix; n_blocks=0 already raised, but with an unhelpful ZeroDivisionError.
nspope
force-pushed
the
fix/373-local-pca-validity-gate
branch
from
November 20, 2026 17:49
6e46d87 to
a9bd4d3
Compare
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.
Closes #373
local_pca(every engine) andlocal_pca_jackknifedecided window validity fromwindow.n_variants, counted beforemissing_data='exclude'removed incomplete sites, so a window with no complete site looked valid and got degenerate eigvals/sumsq/eigvecs instead of NaN._local_pca_with_jackknife's jackknife gate also compared againstX.shape[1](one-hot columns), which can exceed the real site count, so it could disagree withlocal_pca_jackknifeon the same window._centered_block/_prepare_centerednow also return the site count left after the exclude filter, and all four window-processing paths re-gate on it instead of the pre-filter or one-hot-column counts. Block splitting inside the jackknife still operates on X's own columns, since that's what's actually indexed.