Skip to content

refactor: share the hrp/schur_hrp pipeline and narrow hrp.__all__ (#815) - #818

Merged
tschm merged 2 commits into
mainfrom
rhiza_fix_815_20261001
Oct 1, 2026
Merged

tschm merged 2 commits into
mainfrom
rhiza_fix_815_20261001

Conversation

@tschm

@tschm tschm commented Oct 1, 2026

Copy link
Copy Markdown
Owner

Fixes #815.

Acceptance criterion (verbatim):

each public entry point is one prepare call plus one allocator call, compute_corr isn't called when a node is passed, and __init__ imports each name from the module that owns it.

What changed

  • src/pyhrp/hrp.py
    • New private _prepare(prices, node, method, bisection) -> (cov, node). It computes returns and the finite covariance matrix, and only builds the correlation matrix and tree when node is None (this replaces node or …).
    • hrp and schur_hrp now each make one _prepare call plus one allocator call.
    • __all__ narrowed to ["hrp", "schur_hrp"].
    • Dendrogram, build_tree, compute_corr and compute_cov stay importable from pyhrp.hrp through explicit X as X re-exports. docs/api.md, the marimo notebooks, book/scripts/demo.py and the doctests in algos.py/plot.py all import from that path.
    • The linkage Literal was repeated in both signatures; it is now a single Method alias.
    • Module docstring updated to say which module owns which name.
  • src/pyhrp/__init__.py: imports compute_* from covariance, Dendrogram/build_tree from dendrogram, and hrp/schur_hrp from hrp.

Gates

  • make fmt: pass (ruff, mypy, interrogate, bandit, …)
  • make typecheck: ty and mypy --strict both pass
  • make test: 132 passed, 1 skipped; coverage 100% (lines and branches; both branches of if node is None are covered by the existing tests)
  • make rhiza-test: 29 passed, 6 skipped (dynamic version); the docstring examples pass

Not addressed

  • check_finite_matrix is no longer re-exported from pyhrp.hrp's __all__. It is still importable from there because hrp.py uses it, and its owner is pyhrp.covariance. Nothing in the repo imported it through pyhrp.hrp.
  • No test asserts that compute_corr is skipped when a node is passed; the criterion is met in code (see _prepare).
  • This touches the same functions as Add doctest examples to hrp() and schur_hrp() #816 (doctests for hrp/schur_hrp), so I held Add doctest examples to hrp() and schur_hrp() #816 back until this merges.

Closes #815

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 45 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: f6772285-589d-4adc-9b68-a97dc0fed526

📥 Commits

Reviewing files that changed from the base of the PR and between f09d0ed and 2cb792f.

📒 Files selected for processing (2)
  • src/pyhrp/__init__.py
  • src/pyhrp/hrp.py
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@tschm
tschm merged commit 0867d85 into main Oct 1, 2026
57 of 61 checks passed
@tschm
tschm deleted the rhiza_fix_815_20261001 branch October 1, 2026 07:26
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.

De-duplicate the hrp/schur_hrp pipeline and narrow hrp.__all__ to what hrp.py owns

1 participant