bugger.
All challenges/Pythonmediumgsoc-sktime-expanding-cutoff-v1
THE INVESTIGATION

The backtest step that creates one fold too many

An expanding-window backtest checks the current forecast window before taking a larger step, then emits test indices beyond the series.

MLUpstream bugssktimeTime-series splitting

What’s going wrong

ML practice. Historical teaching adaptation of a repaired sktime defect, written independently for Bugger. This is not an official GSoC task or a currently open issue to resubmit.

A backtest generates an invalid final fold when the cutoff advances by more than one position. Its current horizon fits, but the next cutoff can put a requested test observation outside the series. Repair expanding_folds to keep every emitted fold within the available data. The starter prints the invalid indices instead of indexing a dataset, so the defect remains visible without a runtime crash.

Input is {"length":9,"initial_cutoff":1,"horizon":[1,3],"step":3}. The series has zero-based indices 0 through length-1. A cutoff c is the inclusive end of training, so train contains every index from 0 through c. A positive horizon offset h selects test index c+h. Every requested offset must fit; never emit a partial test window, clip an index or discard an offset. Preserve the given horizon order and any repeated offsets.

Emit the initial cutoff only if its entire test window fits. If it does not fit, return no folds. After an emitted cutoff c, consider the next cutoff c+step. Emit that next fold only if all of its requested test indices are smaller than length; otherwise stop. Continue by the same fixed step without shifting the initial cutoff to fit.

Print {"folds":[{"train":[0,1],"test":[2,4]},...]}, in increasing cutoff order. length is an integer from 1 to 60; initial_cutoff is an integer from 0 through length-1; step is an integer from 1 to 60; horizon is a list of 1 to 6 integer offsets, each from 1 to 60. Inputs satisfy these bounds. An in-range initial_cutoff may legitimately yield no folds when its horizon does not fit.

Expected behavior

Emit only complete expanding-window folds whose future test indices fit the series, including the first fold when valid and considering the full next step before appending another cutoff.

Reproduction

01 The next step would place the final horizon outside the series
{"length":9,"initial_cutoff":1,"horizon":[1,3],"step":3}
{"folds":[{"train":[0,1],"test":[2,4]},{"train":[0,1,2,3,4],"test":[5,7]}]}
02 Unit steps keep the ordinary expanding folds
{"length":5,"initial_cutoff":1,"horizon":[1,2],"step":1}
{"folds":[{"train":[0,1],"test":[2,3]},{"train":[0,1,2],"test":[3,4]}]}
03 The supplied horizon order is preserved
{"length":8,"initial_cutoff":2,"horizon":[3,1],"step":2}
{"folds":[{"train":[0,1,2],"test":[5,3]},{"train":[0,1,2,3,4],"test":[7,5]}]}

Before you begin

  • Zero-based and inclusive indices
  • Expanding-window backtests
  • Loop guards and lookahead

Need a nudge?

Reveal one investigation hint at a time. Try each clue before opening the next.

    The bug is intentional. Run the starter code to see it fail, then work toward a fix. Difficulty is provisional.
    Read-only preview
    Ready when you are
    Every fix starts with a failing test.

    Read the report, then sign in to start your investigation.