Skip to content

Add a build_prediction_frame(y_pred, time, unit, level) factory to the leaf #113

Description

@Polichinel

Driver: the views-frames adoption across the platform (views-pipeline-core #188 → 3.0.0; engine repos views-hydranet/views-baseline migrating their PF construction). An expert-code-review concluded that a frame-construction convenience belongs in the leaf (where the type lives), NOT re-published from a consumer package like pipeline-core. This issue is that leaf-side factory.

What

A thin convenience constructor that returns a real PredictionFrame so callers don't have to build the SpatioTemporalIndex themselves:

def build_prediction_frame(y_pred, time, unit, level: SpatialLevel,
                           metadata: FrameMetadata | None = None) -> PredictionFrame:
    index = SpatioTemporalIndex(time=..., unit=..., level=level)
    return PredictionFrame(y_pred, index, metadata)

(Exact signature/dtype-coercion is the maintainer's call — match the leaf's existing validation conventions.)

Why in the leaf, not pipeline-core

  • It's frame-construction knowledge → it belongs with the frame (single-homed contract; no forked construction API across packages).
  • Engines then bind their construction to the API-frozen leaf (most stable node), not to pipeline-core's faster release cadence.
  • It retires the duplicated local build_prediction_frame in views-baseline (views_baseline/model/helpers.py:110).

Notes / scope

  • API-frozen (ADR-018): this is an additive convenience (new public function), so a minor release suffices; no break.
  • Optional/lower-priority: engines can migrate today by constructing SpatioTemporalIndex directly (the hydranet/baseline issues do this). This factory just shrinks those call sites to one line once released.

DoD

from views_frames import build_prediction_frame returns a conformant PredictionFrame; covered by the leaf's own tests; released so engines + views-baseline can adopt it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions