Skip to content

fix: keep invalid margin schedules scalar#33

Merged
stefan-jansen merged 1 commit into
mainfrom
fix/margin-schedule-sequence-serialization
Jul 11, 2026
Merged

fix: keep invalid margin schedules scalar#33
stefan-jansen merged 1 commit into
mainfrom
fix/margin-schedule-sequence-serialization

Conversation

@stefan-jansen

Copy link
Copy Markdown
Contributor

Summary

  • serialize invalid margin schedule values element-wise only for tuple/list values
  • keep strings, mappings, and iterators scalar to avoid corrupting export output or consuming arbitrary iterables
  • add regression coverage for string, dict, and generator invalid schedule values

Verification

  • uv run pytest tests/test_config_wiring.py::TestImmediateFill::test_invalid_margin_pct_schedule_export_keeps_non_sequences_scalar tests/test_config_wiring.py::TestImmediateFill::test_margin_pct_schedule_float_overflow_is_reported tests/test_config_wiring.py::TestImmediateFill::test_invalid_margin_pct_schedule_export_does_not_raise -q
  • pre-commit run --files src/ml4t/backtest/config.py tests/test_config_wiring.py

Copilot AI review requested due to automatic review settings July 11, 2026 18:14

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

This PR adjusts BacktestConfig.to_dict() export behavior for invalid margin_pct_schedule entries so that only list/tuple invalid values are serialized element-wise, while strings, mappings, and iterators are preserved as scalars to avoid corrupting exports or consuming arbitrary iterables.

Changes:

  • Update invalid margin schedule serialization to only expand list/tuple values element-wise.
  • Keep non-list/tuple invalid values (e.g., str, dict, generators) scalar via _serialize_invalid_margin_scalar.
  • Add regression coverage for invalid schedule values that are non-sequences (string, dict, generator).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/ml4t/backtest/config.py Changes invalid margin schedule serialization to only iterate list/tuple values.
tests/test_config_wiring.py Adds a regression test for exporting invalid schedule values that are non-sequence types.

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

Comment thread tests/test_config_wiring.py
@stefan-jansen stefan-jansen merged commit c19ad30 into main Jul 11, 2026
8 checks passed
@stefan-jansen stefan-jansen deleted the fix/margin-schedule-sequence-serialization branch July 11, 2026 18:19
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