Skip to content

feat(tl): add sum method to ancestral_states#54

Merged
colganwi merged 1 commit intomainfrom
feat/ancestral-states-sum
Mar 30, 2026
Merged

feat(tl): add sum method to ancestral_states#54
colganwi merged 1 commit intomainfrom
feat/ancestral-states-sum

Conversation

@colganwi
Copy link
Copy Markdown
Collaborator

Summary

  • Adds a sum method to ancestral_states that computes the sum of leaf values in each node's subtree.
  • Uses an iterative bottom-up traversal via reversed(nx.topological_sort(...)) — O(n), no recursion, no intermediate list storage.
  • Respects fixed_nodes (fixed internal nodes are treated as leaves).
  • Guards against non-numeric dtypes (same as mean).
  • Works for both scalar and array keys.

Test plan

  • test_ancestral_states_sum — scalar values summed correctly up tree1 and tree2
  • test_ancestral_states_sum_array — array (spatial) values summed element-wise
  • test_ancestral_states_sum_fixed_nodes — fixed internal nodes are not overwritten

🤖 Generated with Claude Code

… traversal

Uses reversed topological sort for efficient O(n) aggregation without
recursion or intermediate list storage. Respects fixed_nodes and array keys.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 30, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.95%. Comparing base (4d64ddc) to head (41dfed3).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #54      +/-   ##
==========================================
+ Coverage   93.92%   93.95%   +0.02%     
==========================================
  Files          35       35              
  Lines        2932     2943      +11     
==========================================
+ Hits         2754     2765      +11     
  Misses        178      178              
Files with missing lines Coverage Δ
src/pycea/tl/ancestral_states.py 97.22% <100.00%> (+0.14%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@colganwi colganwi merged commit 186823e into main Mar 30, 2026
8 checks passed
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