climate_ref.results.frames
#
DataFrame conversion and facet collection for metric values.
These pure helpers are the single source of truth for the column layout of a metric-value frame.
Both the collections' to_pandas() and any other consumer build their frames here,
so a scalar (or series) frame has identical columns.
The builders take detached DTOs (from climate_ref.results.values) rather than ORM rows,
so they never touch a session and are portable.
collect_facets(session, stmt, entity)
#
Distinct non-null values for each registered CV dimension of a filtered query.
Runs one DISTINCT per dimension over the (pre-pagination) stmt so cost scales with
cardinality rather than row count. Returns only dimensions that have at least one value.
Source code in packages/climate-ref/src/climate_ref/results/frames.py
scalar_values_to_frame(values, *, detection_ran=False)
#
Flatten scalar value DTOs to a tidy DataFrame.
One row per value; one column per CV dimension present, plus id, execution_id,
execution_group_id, kind and value.
kind is promoted out of the dimension columns.
Outlier columns (is_outlier/verification_status) are added only when detection_ran is set,
and context columns (diagnostic_slug/provider_slug) only when populated on the DTOs.
value is left raw (NaN/inf preserved).
Source code in packages/climate-ref/src/climate_ref/results/frames.py
series_values_to_frame(values, *, explode=True)
#
Flatten series value DTOs to a DataFrame.
With explode=True (default) the result is long-form: one row per (series, index point),
with columns value and index in addition to the shared metadata.
With explode=False each series is one row with list-valued values/index cells.
Shared columns are the CV dimensions present plus id, execution_id, execution_group_id,
kind, index_name and reference_id.
Context columns (diagnostic_slug/provider_slug) are added only when populated on the DTOs.