Skip to content

fix: normalise loaded handles to PeriodIndex so seasonal forecasters work (#531) - #542

Open
Shashankss1205 wants to merge 1 commit into
mainfrom
fix/531-periodindex-normalization
Open

fix: normalise loaded handles to PeriodIndex so seasonal forecasters work (#531)#542
Shashankss1205 wants to merge 1 commit into
mainfrom
fix/531-periodindex-normalization

Conversation

@Shashankss1205

Copy link
Copy Markdown
Collaborator

Fixes #531.

Problem

load_data_source produced a DatetimeIndex with freq "MS" (MonthBegin) for monthly data. Seasonal forecasters (sp>1) coerce the index to a PeriodIndex internally via index.to_period(freq) and raise <MonthBegin> is not supported as period frequency — so fit succeeded and predict failed, with no signal at fit time and no workaround inside the toolset. The same root cause broke evaluate on handle data and demo-fit + handle-update interop (NB-19).

Fix

Normalise a regular DatetimeIndex to PeriodIndex at load, matching sktime's demo datasets (which carry a PeriodIndex and work end-to-end). Key detail: to_period() is called with no argument so pandas maps the offset to its period alias (MS"M"); passing the inferred "MS" string back in re-raises the same error. No-op for irregular indexes, already-PeriodIndex, or non-datetime indexes.

Applied in format_data_handle (the auto-format-on-load path) and in the auto-format-disabled fallback, so it holds regardless of SKTIME_MCP_AUTO_FORMAT.

Testing

  • New tests/test_periodindex_normalization.py (7 tests): the helper across MS/inferred/irregular/period inputs; load yields a PeriodIndex; the exact reported repro (fit(NaiveForecaster(sp=12), y_handle)predict(horizon=6)) now succeeds; seasonal evaluate on a handle returns real (non-NaN) metrics.
  • Verified split_data, save_data, plot_series, inspect_data all still work on period-indexed handles (cutoff 2021-12, 24/6 split, CSV 30 rows, 2-series plot).
  • Full suite: 250 passed.

Verify over the wire (after server restart)

load_data_source(24+ monthly rows) -> fit(NaiveForecaster(sp=12), y_handle) -> predict(horizon=6)

must return a forecast (previously errored at predict).

🤖 Generated with Claude Code

…work (#531)

load_data_source produced a DatetimeIndex with freq "MS" (MonthBegin) for
monthly data. Seasonal forecasters (sp>1) coerce the index to a PeriodIndex
internally via index.to_period(freq) and raise "<MonthBegin> is not supported
as period frequency" — so fit succeeded and predict failed, with no signal at
fit time and no in-toolset workaround. This also broke evaluate and
demo-fit + handle-update (NB-19) for the same reason.

Normalise a regular DatetimeIndex to PeriodIndex at load, matching sktime's
demo datasets (which carry a PeriodIndex and work). to_period() is called with
no argument so pandas maps the offset to its period alias (MS -> "M"); passing
the offset string back would re-raise the same error. No-op for irregular
indexes, already-PeriodIndex, or non-datetime indexes. Applied in
format_data_handle (the auto-format-on-load path) and in the
auto-format-disabled fallback.

Verified: split_data, save_data, plot_series, inspect_data all still work on
the period-indexed handles. Fixes #531; unblocks NB-19.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

[BUG] Seasonal forecasting broken on user-loaded monthly data (MS DatetimeIndex vs PeriodIndex)

1 participant