Estimates: each risk's interval when the model gives one; a member it can't place has no rows

A run with `risk_interval_level` has a model that gives, after the risk at each horizon, its interval's lower and
upper ends; the estimate keeps them as `ic_bajo` and `ic_alto`, the contract checks that they hold the risk, and the
batch stores them. `scored_frame` is the one place that reads the run and calls the model, for the command and the
WebApi's cycle. A member whose risk is NaN (a combination the model never saw) is left out instead of stopping the
whole batch.
This commit is contained in:
2026-11-22 07:38:17 -06:00
parent 271c799d0a
commit 78a4748592
5 changed files with 95 additions and 22 deletions
+11 -3
View File
@@ -75,11 +75,19 @@ def test_each_row_becomes_one_risk_at_its_horizon():
(2, d2, 3.0, 0.23, None, None)]
def test_a_risk_keeps_the_interval_the_model_gave():
"""Pins down: an estimate with `ic_bajo` and `ic_alto` stores them with each risk, and NaN (a member the model
couldn't bound) is stored as no interval. Fails if `risk_rows` drops the interval or stores NaN."""
frame = _estimate((1, 2)).assign(ic_bajo=[0.05, float("nan")], ic_alto=[0.2, float("nan")])
assert [row[4:] for row in risk_rows(frame)] == [(0.05, 0.2), (None, None)]
@pytest.mark.parametrize("frame", [_estimate((1, 1)), _estimate().assign(probabilidad=[0.1, 1.5, 0.2]),
_estimate().rename(columns={"probabilidad": "p"})])
_estimate().rename(columns={"probabilidad": "p"}),
_estimate().assign(ic_bajo=[0.2, 0.1, 0.3], ic_alto=[0.3, 0.3, 0.4])])
def test_a_malformed_estimate_stops_the_batch(frame):
"""Pins down: a member scored twice at one horizon, a probability outside 0..1, or other columns stop the batch
before anything is written. Fails if any of them reaches the database."""
"""Pins down: a member scored twice at one horizon, a probability outside 0..1, other columns, or an interval that
doesn't hold its risk stop the batch before anything is written. Fails if any of them reaches the database."""
with pytest.raises(ValueError):
risk_rows(frame)