Skip to content

S1 — frames.py: generalize to_prediction_frame to S>1 (pandas→frames) #86

Closed

Description

@Polichinel

Epic: #85 · S1 · [UNILATERAL] · ← recommended first step

Background

unfao/frames.py is the (currently unused) views-frames conformance adapter. to_prediction_frame reshapes a single scalar column to (N, 1) via _column_2d(...).reshape(-1, 1) (frames.py:79-85) — i.e. it hardcodes S=1 (point estimates). The forecast PGMDataset already holds per-cell sample arrays in object-dtype cells (pipeline-core _convert_to_arrays), so the samples exist; the adapter just can't represent them. This is the keystone capability: nothing else in the migration can carry (N,S) until the adapter can.

Work

  • Add a path to to_prediction_frame that detects an object-dtype column whose cells are 1-D sample arrays and stacks them into a contiguous (N, S) float32 array, asserting uniform S across rows, and builds a PredictionFrame((N,S), index).
  • Keep the existing scalar → (N, 1) path byte-identical.
  • to_target_frame stays (N, 1) (TargetFrame is S=1 by contract).

Acceptance criteria

  • An object-dtype sample column converts to a PredictionFrame with sample_count == S and values == np.stack(cells) (float32).
  • The scalar path is unchanged: sample_count == 1, values[:, 0] equals the source column.
  • assert_frame_contract(pf) passes for both (float32, explicit trailing axis, int identifiers length N, save/load round-trip).

Parity / validation

Extend tests/test_views_frames_conformance.py (the established build pandas → convert → assert arrays equal pattern):

  • regression leg: existing scalar test stays green untouched (the parity oracle).
  • new leg: synthetic object-dtype frame (cells = small numpy sample arrays) → assert values == np.stack(cells) + assert_frame_contract.

Dependencies

None. Blocks S2 and S3. Lowest risk: the module is unused in production and guarded by the conformance suite.

Files

views_postprocessing/unfao/frames.py (to_prediction_frame, _column_2d), tests/test_views_frames_conformance.py.


Review amendment (expert-code-review, 2026-06-28)

Once this lands, frames.py moves from the unused conformance adapter to a live-path module — so add to the acceptance criteria:

  • Add a CIC for the adapter (ADR-006: it is now a non-trivial live contract), documenting the scalar→(N,1) and sample→(N,S) behaviours.
  • Flip register C-45 (which tracks frames.py as "unused / on no live path") — update or resolve it, since the module is now wired in.

✅ Approved design — Option D (declare-don't-guess, 2026-06-28)

This supersedes the "detect an object-dtype column and stack" wording in the Work section above. frames.py must not infer the sample shape by sniffing dtypes — the caller declares it and the constructor fails loud on mismatch.

Design:

Acceptance criteria (replacing the inference-based ones):

  • frames.py constructs a PredictionFrame from a declared (N,S) float32 array + index; raises (fail-loud) if the array's shape/dtype doesn't match what was declared. No dtype sniffing anywhere.
  • The scalar/point path stays byte-identical (sample_count == 1).
  • frames.py no longer imports pandas (representation-free).
  • CIC for the now-live adapter; flip register C-45.
  • Parity: existing conformance test green; new leg asserts values equals the explicitly-passed (N,S) array (no stacking inference under test).

Activity

  1. added
    story
    implementation
    on Jun 28, 2026
  2. added 2 commits that reference this issue on Jun 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    implementationstory

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions