diff --git a/src/figures.py b/src/figures.py index e96946a..4641c61 100644 --- a/src/figures.py +++ b/src/figures.py @@ -769,7 +769,10 @@ def compute_considerations_stats(lff: pl.LazyFrame) -> dict[str, tuple[int, int] for key, col in present.items(): count_pos = agg.filter(pl.col(col).str.contains(CONSIDERATIONS_REGEX)).height count_ren = agg.filter(pl.col(col).is_not_null()).height - pct_pos_ren = round(100 * count_pos / count_ren) if count_ren > 0 else 0 + count_pos_ren = agg.filter( + pl.col(col).is_not_null() & (pl.col(col) != "Sans objet") + ).height + pct_pos_ren = round(100 * count_pos_ren / count_ren) if count_ren > 0 else 0 stats[key] = (count_pos, round(100 * count_pos / total)) stats[f"{key}_renseignees"] = (count_ren, pct_pos_ren) diff --git a/tests/test_figures.py b/tests/test_figures.py index 0ccc82a..040c92e 100644 --- a/tests/test_figures.py +++ b/tests/test_figures.py @@ -42,9 +42,10 @@ def test_compute_considerations_stats_basic(): # 4 marchés au total. Social : u1, u3 -> 2/4 = 50%. Env : u2 -> 1/4 = 25%. assert stats["sociales"] == (2, 50) assert stats["environnementales"] == (1, 25) - # Renseignées : dénominateur = non-null ; numérateur = positifs. - # Social : 4 non-null, 2 positifs -> (4, 50%). Env : 3 non-null, 1 positif -> (3, 33%). - assert stats["sociales_renseignees"] == (4, 50) + # Renseignées : dénominateur = non-null ; numérateur = non-null ET != "Sans objet". + # Social : 4 non-null, 3 != "Sans objet" (u1/u3/u4) -> (4, 75%). + # Env : 3 non-null, 1 != "Sans objet" (u2) -> (3, 33%). + assert stats["sociales_renseignees"] == (4, 75) assert stats["environnementales_renseignees"] == (3, 33)