From 2f7202987dadf021c3dac36f44c704557404b77d Mon Sep 17 00:00:00 2001 From: Marcus Baw Date: Sat, 5 Sep 2026 18:57:50 +0100 Subject: [PATCH 1/2] fix: align Trisomy 21 BMI upper bound --- .../test_trisomy_21_reference_boundaries.py | 34 +++++++++++++++++++ rcpchgrowth/trisomy_21.py | 6 ++-- 2 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 rcpchgrowth/tests/test_trisomy_21_reference_boundaries.py diff --git a/rcpchgrowth/tests/test_trisomy_21_reference_boundaries.py b/rcpchgrowth/tests/test_trisomy_21_reference_boundaries.py new file mode 100644 index 0000000..e9bdb5e --- /dev/null +++ b/rcpchgrowth/tests/test_trisomy_21_reference_boundaries.py @@ -0,0 +1,34 @@ +import math + +import pytest + +from rcpchgrowth.constants import BMI, FEMALE, MALE, TRISOMY_21 +from rcpchgrowth.global_functions import sds_for_measurement + + +@pytest.mark.parametrize("sex", [MALE, FEMALE]) +@pytest.mark.parametrize("age", [18.83, 18.92]) +def test_trisomy_21_bmi_accepts_final_source_ages(sex, age): + result = sds_for_measurement( + reference=TRISOMY_21, + age=age, + measurement_method=BMI, + observation_value=25.0, + sex=sex, + ) + + assert math.isfinite(result) + + +@pytest.mark.parametrize("sex", [MALE, FEMALE]) +def test_trisomy_21_bmi_rejects_age_after_last_source_age(sex): + with pytest.raises( + LookupError, match=r"Trisomy BMI reference data does not exist > 18\.92 y\." + ): + sds_for_measurement( + reference=TRISOMY_21, + age=math.nextafter(18.92, math.inf), + measurement_method=BMI, + observation_value=25.0, + sex=sex, + ) diff --git a/rcpchgrowth/trisomy_21.py b/rcpchgrowth/trisomy_21.py index c40b47f..67a079f 100644 --- a/rcpchgrowth/trisomy_21.py +++ b/rcpchgrowth/trisomy_21.py @@ -51,8 +51,8 @@ def reference_data_absent( if age > TWENTY_YEARS: # upper threshold of trisomy_21 data return True, "Trisomy 21 reference data does not exist over the age of 20y." - elif measurement_method == BMI and age > 18.82: - return True, f"Trisomy BMI reference data does not exist > 18.82 y." + elif measurement_method == BMI and age > 18.92: + return True, "Trisomy BMI reference data does not exist > 18.92 y." elif measurement_method == HEAD_CIRCUMFERENCE: if age > EIGHTEEN_YEARS: @@ -80,4 +80,4 @@ def select_reference_data_for_trisomy_21(measurement_method:str, sex:str): return_value = trisomy_21_lms_array_for_measurement_and_sex(measurement_method=measurement_method, sex=sex, age=0.0) except: raise LookupError(f"No data for {measurement_method} in the {sex} Trisomy 21 dataset.") - return return_value \ No newline at end of file + return return_value From 83cef2dd10923afa326dd5018eeeca9a6b9c2b0d Mon Sep 17 00:00:00 2001 From: Marcus Baw Date: Thu, 24 Sep 2026 14:45:46 +0100 Subject: [PATCH 2/2] test: align trisomy BMI boundary assertion --- .../tests/test_reference_vectors_and_boundaries.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/rcpchgrowth/tests/test_reference_vectors_and_boundaries.py b/rcpchgrowth/tests/test_reference_vectors_and_boundaries.py index 7fadafd..8954c4d 100644 --- a/rcpchgrowth/tests/test_reference_vectors_and_boundaries.py +++ b/rcpchgrowth/tests/test_reference_vectors_and_boundaries.py @@ -130,7 +130,14 @@ def test_every_reference_includes_its_lower_boundary_and_rejects_below_it( ), (CDC, 2, 1.9999, BMI, MALE, "BMI below 2 years"), (CDC, 3, 3.0001, HEAD_CIRCUMFERENCE, MALE, "head circumference above 3 years"), - (TRISOMY_21, 18.82, 18.8201, BMI, MALE, "BMI reference data"), + ( + TRISOMY_21, + 18.92, + math.nextafter(18.92, math.inf), + BMI, + MALE, + "BMI reference data", + ), (TRISOMY_21, 18, 18.0001, HEAD_CIRCUMFERENCE, MALE, "head circumference"), (TRISOMY_21_AAP, 0.083333333, 0.0829, HEIGHT, MALE, "below 1 month"), (TRISOMY_21_AAP, 2, 1.9999, BMI, MALE, "below 2 years"),