Repository navigation
Description
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_framethat 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 aPredictionFrame((N,S), index). - Keep the existing scalar →
(N, 1)path byte-identical. to_target_framestays(N, 1)(TargetFrame is S=1 by contract).
Acceptance criteria
- An object-dtype sample column converts to a
PredictionFramewithsample_count == Sandvalues == 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.pyas "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:
frames.pyconstructors take declared primitives — an explicit(N, S)float32 array + the(time, unit)index arrays — and just construct thePredictionFrame, asserting the declared shape and raising on mismatch. No pandas, no dtype inspection, no branching-on-content.- As a consequence
frames.pydrops its pandas import and becomes representation-free (sitting alongsidedelivery/), withextractionthe lone pandas seam. - The pandas→
(N, S)unpacking lives in the extraction seam (S2 — extraction.py: frame-native sibling readers #87), which is told the layout (which columns / which sample column) — it does not guess. - WET / no speculative generality: implement only the one real sample layout, and that layout is defined by rusty_bucket (fix(register): C-62 — corrected measurements and the actual removal path #143). Until fix(register): C-62 — corrected measurements and the actual removal path #143 declares it, S1 ships the frame-wrap capability + the point
(N,1)path (byte-identical to today); the sample-unpacking slots into the seam when fix(register): C-62 — corrected measurements and the actual removal path #143 lands.
Acceptance criteria (replacing the inference-based ones):
-
frames.pyconstructs aPredictionFramefrom 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.pyno longer imports pandas (representation-free). - CIC for the now-live adapter; flip register C-45.
- Parity: existing conformance test green; new leg asserts
valuesequals the explicitly-passed(N,S)array (no stacking inference under test).
Activity
docs(risk-register): cross-link C-40 to the pandas-migration epic (#85)
Merge pull request #94 from views-platform/feat/s1-frames-declared-pr…