Skip to content

feat: use common syntaxis and improve speed - #2

Open
AzulGarza wants to merge 2 commits into
mainfrom
feat/improve-speed
Open

feat: use common syntaxis and improve speed#2
AzulGarza wants to merge 2 commits into
mainfrom
feat/improve-speed

Conversation

@AzulGarza

Copy link
Copy Markdown
Member

this pr normalizes syntaxis and improves speed

@cursor

cursor Bot commented Aug 17, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

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 introduces a pre-processed “panel” representation of the input DataFrame to reduce repeated per-model/per-call data processing, and refactors several forecast implementations to reuse that shared panel and common quantile-column assignment utilities.

Changes:

  • Add PanelData + process_panel_from_df() and update TimeSeriesDataset to build from a pre-processed panel (with lazy tensor materialization).
  • Thread an optional panel argument through multiple model forecast() implementations and MultiModelForecasterMixin to reuse shared preprocessing work.
  • Refactor quantile column assignment and several joins/aggregations to use utilsforecast helpers; add/adjust tests for new dataset/panel behavior and quantile→level mapping.

Reviewed changes

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

Show a summary per file
File Description
tests/test_foundation_forecast.py Updates test forecaster stubs to accept the new optional panel kwarg.
tests/helpers.py Updates helper forecasters to accept panel for compatibility with new calling conventions.
tests/core/test_utils.py Adds tests for process_panel_from_df() and TimeSeriesDataset.from_panel() behavior (order, values, laziness).
tests/core/test_forecaster.py Updates expected behavior for quantile-derived level (excluding median-only / median level).
foundationforecast/models/toto.py Accepts optional panel, uses shared dataset builder and shared quantile assignment helper.
foundationforecast/models/tirex.py Accepts optional panel, uses shared dataset builder and shared quantile assignment helper.
foundationforecast/models/timesfm.py Accepts optional panel (currently unused in one path) and uses shared dataset builder in v2 path.
foundationforecast/models/timegpt.py Accepts optional panel (unused) to align with common forecast signature.
foundationforecast/models/tabpfn.py Accepts optional panel (unused) to align with common forecast signature.
foundationforecast/models/t0.py Accepts optional panel and uses shared dataset builder.
foundationforecast/models/sundial.py Accepts optional panel, uses shared dataset builder and shared quantile assignment helper.
foundationforecast/models/patchtst_fm.py Accepts optional panel, uses shared dataset builder and shared quantile assignment helper.
foundationforecast/models/flowstate.py Accepts optional panel, uses shared dataset builder and shared quantile assignment helper.
foundationforecast/models/chronos.py Accepts optional panel, reuses it for finetuning inputs, uses shared dataset builder and quantile assignment helper.
foundationforecast/core/utils.py Adds PanelData, process_panel_from_df, grouped_std_by_id, and refactors TimeSeriesDataset to operate on panel arrays with lazy tensors.
foundationforecast/core/multi_model.py Precomputes panel once per multi-model forecast call; switches merge to utilsforecast.processing.join.
foundationforecast/core/gluonts_forecaster.py Vectorizes forecast→DataFrame conversion using panel ordering and batched column assignment.
foundationforecast/core/forecaster.py Adds shared helpers for dataset construction and quantile-column assignment; uses faster utilsforecast aggregations/joins; adjusts quantile→level mapping logic.
foundationforecast/core/init.py Exposes PanelData, process_panel_from_df, and grouped_std_by_id from the core package.
Suppressed comments (1)

foundationforecast/core/forecaster.py:179

  • panel is being passed through MultiModelForecasterMixin and added to many concrete forecast implementations, but the base Forecaster.forecast signature doesn’t accept it. This makes the public API inconsistent and breaks static typing / interface expectations. Consider adding panel: PanelData | None = None to the base method signature as well.
    def forecast(
        self,
        df: pd.DataFrame,
        h: int,
        freq: str | None = None,
        level: list[int | float] | None = None,
        quantiles: list[float] | None = None,
    ) -> pd.DataFrame:

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread foundationforecast/models/timegpt.py
Comment thread foundationforecast/models/tabpfn.py

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

Copilot reviewed 19 out of 19 changed files in this pull request and generated no new comments.

Suppressed comments (3)

foundationforecast/core/forecaster.py:176

  • The base Forecaster.forecast signature does not accept the new panel argument, but MultiModelForecasterMixin now passes panel to models and several built-in models have been updated to accept it. This makes the core interface inconsistent and can break custom Forecaster subclasses when used via MultiModelForecasterMixin (unexpected panel kwarg) and also causes type-checking signature mismatches.
    def forecast(
        self,
        df: pd.DataFrame,
        h: int,
        freq: str | None = None,

foundationforecast/models/chronos.py:345

  • When finetuning_config is enabled and panel is not provided, the code will compute the panel twice: once inside _make_timeseries_dataset(..., panel=None) (via TimeSeriesDataset.from_df) and again inside _maybe_finetune(..., panel=None) (via _build_fit_inputs_from_df). Computing panel once here and reusing it avoids duplicate preprocessing and aligns with the PR's speed goals.
        freq = self._maybe_infer_freq(df, freq)
        qc = QuantileConverter(level=level, quantiles=quantiles)
        dataset = self._make_timeseries_dataset(
            df,
            batch_size=self.batch_size,

foundationforecast/models/timesfm.py:201

  • panel is already used below (passed into _make_timeseries_dataset(..., panel=panel)), so this _ = panel line is redundant and adds an unnecessary executed statement inside the hot path.
        _ = panel

@elmartinj

Copy link
Copy Markdown
Collaborator

Heads up: I opened #18 as a refreshed copy of this PR on top of current main. Your two commits are preserved, plus a fix commit that addresses the old CI failures (quantile column assignment), updates the newer models (Tafsut, TimesFM 3.0), and aligns the base/mixin signatures. Happy to keep working on #18 or apply changes directly here if you prefer — this branch was left untouched.

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.

3 participants