Skip to content

Fix Flow.flow() returning all-NaN corrected columns with a non-default index - #8

Merged
annmoel merged 1 commit into
masterfrom
fix/flow-corrected-column-nan-with-custom-index
Jul 28, 2026
Merged

annmoel merged 1 commit into
masterfrom
fix/flow-corrected-column-nan-with-custom-index

Conversation

@annmoel

@annmoel annmoel commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

Summary

Reported externally, with a precise root-cause diagnosis and a 20-row repro. Flow.flow() silently returned all-NaN "BOSPERRUS corrected {measure}" columns whenever scores/distances carried 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 rebuilt S_corrected against a bare range(N) index, regardless of S_true's actual index.
  • Flow.flow() stripped the real index via .values before constructing Fit instances, so Fit never even saw it.
  • self.observations[col] = best_fit.S_corrected then tried to label-align a range(N)-indexed Series against observations's real (non-overlapping) index — nothing matched, so the whole column came back NaN.

Fix, both ends:

  • Flow.flow() now passes the real-indexed Series into Fit instead of .values.
  • _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) — so direct Fit usage (bypassing Flow) is unaffected either way.

Test plan

  • Reproduced with a 20-row synthetic example (string index, mimicking adata.obs_names) — confirmed all-NaN before the fix, correct values after
  • pytest tests/ — 117 passed, 1 skipped (1 new regression test: test_flow_preserves_non_default_index)

🤖 Generated with Claude Code

…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>
@annmoel
annmoel merged commit f66f8f6 into master Jul 28, 2026
3 checks passed
@annmoel
annmoel deleted the fix/flow-corrected-column-nan-with-custom-index branch July 28, 2026 12:53
@annmoel annmoel mentioned this pull request Jul 28, 2026
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.

1 participant