Fix Flow.flow() returning all-NaN corrected columns with a non-default index - #8
Merged
Merged
Conversation
…t index
Flow.flow() stripped the index via .values before constructing Fit
instances, and Fit._expand_to_original_index() always rebuilt S_corrected
against a bare range(N) index regardless of what index S_true actually
had. For any scores/distances with a non-default index (e.g.
adata.obs_names, the normal case for AnnData-based workflows),
self.observations[f"BOSPERRUS corrected {measure}"] = best_fit.S_corrected
then failed to label-align against observations's real index, silently
producing an all-NaN column.
Fixes both ends: Flow.flow() now passes the real-indexed Series into Fit
instead of .values, and _expand_to_original_index() preserves
S_true_original's own index (falling back to range(N) only for plain
arrays, which have no index to preserve).
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Merged
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.
Summary
Reported externally, with a precise root-cause diagnosis and a 20-row repro.
Flow.flow()silently returned all-NaN"BOSPERRUS corrected {measure}"columns wheneverscores/distancescarried a non-default index (e.g.adata.obs_names— the normal case for any AnnData-based workflow).Root cause, confirmed by reproduction:
Fit._expand_to_original_index()always rebuiltS_correctedagainst a barerange(N)index, regardless ofS_true's actual index.Flow.flow()stripped the real index via.valuesbefore constructingFitinstances, soFitnever even saw it.self.observations[col] = best_fit.S_correctedthen tried to label-align arange(N)-indexed Series againstobservations's real (non-overlapping) index — nothing matched, so the whole column came backNaN.Fix, both ends:
Flow.flow()now passes the real-indexed Series intoFitinstead of.values._expand_to_original_index()preservesS_true_original's own index, falling back torange(N)only for plain arrays (which have no index to preserve) — so directFitusage (bypassingFlow) is unaffected either way.Test plan
adata.obs_names) — confirmed all-NaN before the fix, correct values afterpytest tests/— 117 passed, 1 skipped (1 new regression test:test_flow_preserves_non_default_index)🤖 Generated with Claude Code