Skip to content

Fix backtest ignoring val_length when generating forecasts - #3264

Merged
dennisbader merged 4 commits into
unit8co:masterfrom
vera-rubin:fix/backtest-val-length
Oct 16, 2026
Merged

dennisbader merged 4 commits into
unit8co:masterfrom
vera-rubin:fix/backtest-val-length

Conversation

@vera-rubin

Copy link
Copy Markdown
Contributor

Checklist before merging this PR:

  • Described the bug below.
  • Summarized the updates under Summary.
  • Added an entry under Unreleased in the Changelog.

Summary

With train_length=4 and val_length=2, NaiveMean().backtest() scores four windows instead of the two produced by historical_forecasts() with the same documented parameters. For the series below, we get MAE 2.3125 instead of 2.5.

from darts import TimeSeries
from darts.metrics import mae
from darts.models import NaiveMean

series = TimeSeries.from_values([1., 4., 2., 9., 6., 3., 10., 7.])
NaiveMean().backtest(
    series, train_length=4, val_length=2, metric=mae, show_warnings=False
)

The change passes val_length to the internal historical_forecasts() call.

Other Information

Regression coverage checks generated and precomputed forecasts for both last_points_only modes and zero/nonzero validation lengths. We ran the backtesting suite and existing validation-length tests.

— ChipLab

@dennisbader dennisbader left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for this fix and your first contribution @vera-rubin 🚀
LGTM 💯

@codecov

codecov Bot commented Oct 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.12%. Comparing base (05192e9) to head (684d6c5).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3264   +/-   ##
=======================================
  Coverage   97.12%   97.12%           
=======================================
  Files         175      175           
  Lines       19402    19402           
=======================================
  Hits        18845    18845           
  Misses        557      557           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dennisbader
dennisbader merged commit c93aab5 into unit8co:master Oct 16, 2026
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