Skip to content

fix: align from_dict() defaults with dataclass defaults - #6

Merged
stefan-jansen merged 1 commit into
mainfrom
fix/from-dict-default-parity
Mar 4, 2026
Merged

fix: align from_dict() defaults with dataclass defaults#6
stefan-jansen merged 1 commit into
mainfrom
fix/from-dict-default-parity

Conversation

@stefan-jansen

Copy link
Copy Markdown
Contributor

Summary

  • from_dict({}) previously defaulted to same_bar/close/snapshot, diverging from BacktestConfig() defaults of next_bar/open/incremental
  • This could silently enable look-ahead-biased execution mode in YAML/dict config workflows
  • Added parity test to prevent future drift

Changes

  • config.py: Fixed 3 fallback values in from_dict() to match dataclass defaults
  • test_config_wiring.py: Added TestFromDictDefaultParity test class

from_dict({}) previously defaulted to same_bar/close/snapshot, diverging
from BacktestConfig() defaults of next_bar/open/incremental. This could
silently enable look-ahead-biased mode in YAML/dict config workflows.
Copilot AI review requested due to automatic review settings March 4, 2026 19:17

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Aligns BacktestConfig.from_dict() fallback values with the BacktestConfig() dataclass defaults to prevent unintended execution behavior (including potential look-ahead-biased modes) when configs are loaded from YAML/dicts.

Changes:

  • Updated from_dict() fallbacks for execution_price, execution_mode, and rebalance_mode to match dataclass defaults.
  • Added a parity test to ensure from_dict({}) produces the same defaults as the constructor.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/ml4t/backtest/config.py Fixes from_dict() fallback defaults to match BacktestConfig constructor defaults.
tests/test_config_wiring.py Adds a regression test intended to prevent default drift between constructor and from_dict({}).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/test_config_wiring.py
Comment thread tests/test_config_wiring.py
Comment thread src/ml4t/backtest/config.py
Comment thread src/ml4t/backtest/config.py
@stefan-jansen
stefan-jansen merged commit 146ad25 into main Mar 4, 2026
11 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.

2 participants