A risk carries the model's index date for its member

Risk and risk_rows give (pac_id, fecha_indice, horizonte_anios, probabilidad, ic_bajo, ic_alto), the shape a batch now
stores: the horizons count from the model's index date, taken from the estimate's rows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HmQxVJVNR5FYkPAregGEQ7
This commit is contained in:
2026-11-20 23:02:46 -06:00
parent 410de1d3b7
commit 941ae15a3e
5 changed files with 19 additions and 14 deletions
+5 -4
View File
@@ -5,6 +5,7 @@ Fixtures: no pytest fixtures. `ConstantEstimator` is the smallest class that mee
fixed probability per member and horizon. `Incomplete` lacks `provenance`.
"""
from datetime import date
from models.io.contracts import Provenance, Risk, RiskEstimator
@@ -18,8 +19,8 @@ class ConstantEstimator:
return Provenance(modelo_nombre="constant", modelo_version="1", mlflow_run_id="none", modelo_sha="sha")
def estimate(self, columns: list[str], rows: list[tuple]) -> list[Risk]:
i_pac = columns.index("pac_id")
return [Risk(row[i_pac], h, 0.1) for row in rows for h in (0.0, 1.0)]
i_pac, i_fecha = columns.index("pac_id"), columns.index("fecha_indice")
return [Risk(row[i_pac], row[i_fecha], h, 0.1) for row in rows for h in (0.0, 1.0)]
class Incomplete:
@@ -57,7 +58,7 @@ def test_a_risk_keeps_the_column_names_and_its_interval_is_optional():
Fails if a field is renamed or reordered, or the interval becomes required.
"""
risk = Risk(1, 0.0, 0.25)
risk = Risk(1, date(2025, 1, 1), 0.0, 0.25)
assert Risk._fields == ("pac_id", "horizonte_anios", "probabilidad", "ic_bajo", "ic_alto")
assert Risk._fields == ("pac_id", "fecha_indice", "horizonte_anios", "probabilidad", "ic_bajo", "ic_alto")
assert (risk.ic_bajo, risk.ic_alto) == (None, None)
+5 -3
View File
@@ -66,11 +66,13 @@ def _stored():
def test_each_row_becomes_one_risk_at_its_horizon():
"""Pins down: a risk is `(pac_id, horizonte_anios, probabilidad, None, None)`, one per member and horizon, the
horizon taken from the row. Fails if the horizon is dropped, taken from elsewhere, or the interval is filled with
"""Pins down: a risk is `(pac_id, fecha_indice, horizonte_anios, probabilidad, None, None)`, one per member and
horizon, the index date and the horizon taken from the row. Fails if the horizon is dropped, taken from elsewhere, or the interval is filled with
something the model didn't give."""
d1, d2 = date(2025, 1, 1), date(2025, 1, 2)
assert risk_rows(_estimate((1, 2), horizons=(0.0, 3.0))) == [
(1, 0.0, 0.1, None, None), (1, 3.0, 0.13, None, None), (2, 0.0, 0.2, None, None), (2, 3.0, 0.23, None, None)]
(1, d1, 0.0, 0.1, None, None), (1, d1, 3.0, 0.13, None, None), (2, d2, 0.0, 0.2, None, None),
(2, d2, 3.0, 0.23, None, None)]
@pytest.mark.parametrize("frame", [_estimate((1, 1)), _estimate().assign(probabilidad=[0.1, 1.5, 0.2]),