"""What this module covers: `models.dags.estimation.estimate_frame`, from a model's output to the estimate's rows. Fixtures: none; a two-member cohort frame built in each test. """ from datetime import date import numpy as np import pandas as pd from models.dags.estimation import estimate_frame COHORT = pd.DataFrame({"pac_id": [1, 2], "fecha_indice": [date(2025, 1, 1), date(2025, 2, 1)]}) def test_a_member_the_model_cannot_place_has_no_rows(): """Pins down: a member whose risk is NaN (a combination unseen in training) is left out and the rest keep their rows, so one such member doesn't stop the whole batch. Fails if the NaN reaches the estimate's contract.""" found = estimate_frame(COHORT, np.array([[0.1, 0.2], [np.nan, np.nan]]), [0.0, 1.0]) assert found["pac_id"].tolist() == [1, 1] and found["probabilidad"].tolist() == [0.1, 0.2] def test_with_intervals_the_unplaced_member_is_left_out_too(): """Pins down: with intervals, the risk block decides who is scored and each kept row has its two ends. Fails if the blocks are read in another order or a NaN end drops a member that has a risk.""" output = np.array([[0.1, 0.05, 0.2], [np.nan, np.nan, np.nan]]) found = estimate_frame(COHORT, output, [1.0], intervals=True) assert found[["pac_id", "probabilidad", "ic_bajo", "ic_alto"]].values.tolist() == [[1, 0.1, 0.05, 0.2]]