From cf6274a6bfcd2c42685b550afde7f15dd40274b3 Mon Sep 17 00:00:00 2001 From: Daniel Weindl Date: Fri, 27 Nov 2026 11:33:42 +0100 Subject: [PATCH 1/2] v1 lint: require `nominalValue` for non-estimated parameters `check_parameter_df` only checked that nominal values of non-estimated parameters are convertible to `float`, which accepts NaN, i.e., empty cells. Now, missing values (NaN, `None`, `pd.NA`) are reported. Also fixes the classification of non-estimated parameters for string `estimate` columns, where all parameters were considered non-estimated. Closes #639. Co-Authored-By: Claude Opus 5.5 --- changelog.d/+nominal-value-nan.fix.md | 5 ++++ petab/v1/lint.py | 36 +++++++++++++-------------- tests/v1/test_lint.py | 21 ++++++++++++++++ 3 files changed, 44 insertions(+), 18 deletions(-) create mode 100644 changelog.d/+nominal-value-nan.fix.md diff --git a/changelog.d/+nominal-value-nan.fix.md b/changelog.d/+nominal-value-nan.fix.md new file mode 100644 index 00000000..fd6a52f1 --- /dev/null +++ b/changelog.d/+nominal-value-nan.fix.md @@ -0,0 +1,5 @@ +PEtab v1 validation: `check_parameter_df`, and thus `lint_problem`, now +reports an error for non-estimated parameters with a missing (empty) +`nominalValue`. +As `petab1to2` validates its input, it now rejects such problems +([#XXX](https://github.com/PEtab-dev/libpetab-python/pull/XXX)) diff --git a/petab/v1/lint.py b/petab/v1/lint.py index 9d142af8..9290d77e 100644 --- a/petab/v1/lint.py +++ b/petab/v1/lint.py @@ -249,17 +249,15 @@ def check_parameter_df( df[column_name].values, column_name ) - # nominal value is generally optional, but required if any for any - # parameter estimate != 1 - non_estimated_par_ids = list( - df.index[ - (df[ESTIMATE] != 1) - | ( - pd.api.types.is_string_dtype(df[ESTIMATE]) - and df[ESTIMATE] != "1" - ) - ] - ) + assert_parameter_id_is_string(df) + assert_parameter_scale_is_valid(df) + assert_parameter_bounds_are_numeric(df) + assert_parameter_estimate_is_boolean(df) + assert_unique_parameter_ids(df) + + # nominal value is generally optional, but required for parameters + # with estimate == 0 + non_estimated_par_ids = list(df.index[df[ESTIMATE].apply(int) != 1]) if non_estimated_par_ids: if NOMINAL_VALUE not in df: raise AssertionError( @@ -269,18 +267,20 @@ def check_parameter_df( f"but column {NOMINAL_VALUE} is missing." ) try: - df.loc[non_estimated_par_ids, NOMINAL_VALUE].apply(float) - except ValueError as e: + nominal_values = df.loc[ + non_estimated_par_ids, NOMINAL_VALUE + ].apply(lambda x: np.nan if pd.isna(x) else float(x)) + except (ValueError, TypeError) as e: raise AssertionError( f"Expected numeric values for `{NOMINAL_VALUE}` in parameter " "table for all non-estimated parameters." ) from e + if missing := list(nominal_values.index[nominal_values.isna()]): + raise AssertionError( + f"`{NOMINAL_VALUE}` is required for parameters with " + f"`{ESTIMATE}=0`, but is missing for {missing}." + ) - assert_parameter_id_is_string(df) - assert_parameter_scale_is_valid(df) - assert_parameter_bounds_are_numeric(df) - assert_parameter_estimate_is_boolean(df) - assert_unique_parameter_ids(df) check_parameter_bounds(df) assert_parameter_prior_type_is_valid(df) assert_parameter_prior_parameters_are_valid(df) diff --git a/tests/v1/test_lint.py b/tests/v1/test_lint.py index e62b5505..9bd0351b 100644 --- a/tests/v1/test_lint.py +++ b/tests/v1/test_lint.py @@ -574,6 +574,27 @@ def test_check_parameter_df(): parameter_df[NOMINAL_VALUE] = parameter_df[NOMINAL_VALUE].astype("object") lint.check_parameter_df(df=parameter_df) + # NOMINAL_VALUE missing for estimated parameter is fine + parameter_df.loc["par1", NOMINAL_VALUE] = nan + lint.check_parameter_df(df=parameter_df) + + # NOMINAL_VALUE missing for non-estimated parameter + for missing_value in (nan, None, pd.NA): + parameter_df.loc["par2", NOMINAL_VALUE] = missing_value + with pytest.raises(AssertionError, match=r"missing for \['par2'\]"): + lint.check_parameter_df(df=parameter_df) + # ... with float column, as from `get_parameter_df` + parameter_df.loc["par2", NOMINAL_VALUE] = nan + float_df = parameter_df.astype({NOMINAL_VALUE: float}) + with pytest.raises(AssertionError, match=r"missing for \['par2'\]"): + lint.check_parameter_df(df=float_df) + # ... with string ESTIMATE column + str_df = parameter_df.astype({ESTIMATE: str}) + with pytest.raises(AssertionError, match=r"missing for \['par2'\]"): + lint.check_parameter_df(df=str_df) + str_df.loc["par2", NOMINAL_VALUE] = 1.0 + lint.check_parameter_df(df=str_df) + # NOMINAL_VALUE empty, for non-estimated parameter parameter_df.loc["par2", NOMINAL_VALUE] = "" with pytest.raises(AssertionError): From eeaf78bb683e61db78a4ec402647ef1fccd8636e Mon Sep 17 00:00:00 2001 From: Daniel Weindl Date: Fri, 27 Nov 2026 11:34:02 +0100 Subject: [PATCH 2/2] changelog: PR number Co-Authored-By: Claude Opus 5.5 --- changelog.d/+nominal-value-nan.fix.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.d/+nominal-value-nan.fix.md b/changelog.d/+nominal-value-nan.fix.md index fd6a52f1..105426ae 100644 --- a/changelog.d/+nominal-value-nan.fix.md +++ b/changelog.d/+nominal-value-nan.fix.md @@ -2,4 +2,4 @@ PEtab v1 validation: `check_parameter_df`, and thus `lint_problem`, now reports an error for non-estimated parameters with a missing (empty) `nominalValue`. As `petab1to2` validates its input, it now rejects such problems -([#XXX](https://github.com/PEtab-dev/libpetab-python/pull/XXX)) +([#640](https://github.com/PEtab-dev/libpetab-python/pull/640))