Skip to content

fix(python): constructable GaussianHmmParamsPy + dict-like backtest metrics (nhkk)#12

Merged
lavs9 merged 1 commit into
mainfrom
fix/nhkk-record-ctors
Jul 13, 2026
Merged

fix(python): constructable GaussianHmmParamsPy + dict-like backtest metrics (nhkk)#12
lavs9 merged 1 commit into
mainfrom
fix/nhkk-record-ctors

Conversation

@lavs9

@lavs9 lavs9 commented Jul 13, 2026

Copy link
Copy Markdown
Owner

Two uniffi → PyO3 record-port gaps, surfaced when the previously-CI-invisible tests were relocated to tests/python/ (both confirmed pre-existing on main, not regressions from the FFI work):

  1. GaussianHmmParamsPy had no #[new]. It's an input params record Python constructs (qw.GaussianHmmParamsPy(n_states=…, delta=…, …)), but the ported #[pyclass(get_all)] wasn't constructable → "No constructor defined". Added #[new] (lambdas defaults to empty = Gaussian mode). Audited all 49 records — this is the only one Python constructs; the rest are read-only outputs.
  2. PerformanceMetrics / BacktestStats broke the in operator. They had __getitem__(str) + keys() but no __contains__, so "sharpe_ratio" in metrics fell back to integer-index iteration → TypeError: attribute name must be string, not 'int'. Added __contains__ + __iter__ (now properly dict-like).

Result: fixes test_hmm_forecast (2), test_ml_feature_backtest_parity, test_strategy_backtest. Full suite 6 → 2 failures; the remaining two are unrelated — a pandas-only benchmark test and a stale LazyFrame.ta test_parity.

🤖 Generated with Claude Code

…etrics (nhkk)

Two record-port gaps from the uniffi->PyO3 migration, surfaced by relocating the
previously-CI-invisible tests:

1. GaussianHmmParamsPy is an INPUT params record that Python constructs
   (qw.GaussianHmmParamsPy(n_states=..., delta=..., ...)), but the ported
   #[pyclass(get_all)] had no #[new], so construction raised "No constructor
   defined". Add a #[new] (lambdas defaults to empty = Gaussian mode). Audited all
   49 records: this is the only one Python constructs; the rest are read-only outputs.

2. PerformanceMetrics / BacktestStats define __getitem__(str) + keys() but no
   __contains__, so `"sharpe_ratio" in metrics` fell back to integer-index iteration
   (getattr(self, 0)) -> "TypeError: attribute name must be string, not 'int'".
   Add __contains__ and __iter__ so they behave dict-like.

Fixes test_hmm_forecast (2), test_ml_feature_backtest_parity, test_strategy_backtest.
Full suite 6 -> 2 failures (remaining: pandas-only benchmark test + a stale
LazyFrame.ta test_parity, both unrelated).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@lavs9
lavs9 merged commit 37a511e into main Jul 13, 2026
6 checks passed
@lavs9
lavs9 deleted the fix/nhkk-record-ctors branch July 13, 2026 16:40
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