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)