Skip to content

Commit 3e42f8e

Browse files
authored
Handle missing nominalValue in Problem.get_x_nominal (#223)
It doesn't seem to be quite clear if the `nominalValue` column needs to be present if all parameters are estimated. However, since it's allowed to leave `nominalValue` empty, which is treated as NaN, it seems to make sense to treat a missing `nominalValue` column as all-NaN. See also ICB-DCM/pyPESTO#1104
1 parent d9b1e65 commit 3e42f8e

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

petab/problem.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import os
55
import tempfile
6+
from math import nan
67
from pathlib import Path, PurePosixPath
78
from typing import Dict, Iterable, List, Optional, Union, TYPE_CHECKING
89
from urllib.parse import unquote, urlparse, urlunparse
@@ -660,7 +661,11 @@ def get_x_nominal(self, free: bool = True, fixed: bool = True,
660661
-------
661662
The parameter nominal values.
662663
"""
663-
v = list(self.parameter_df[NOMINAL_VALUE])
664+
if NOMINAL_VALUE in self.parameter_df:
665+
v = list(self.parameter_df[NOMINAL_VALUE])
666+
else:
667+
v = [nan] * len(self.parameter_df)
668+
664669
if scaled:
665670
v = list(parameters.map_scale(
666671
v, self.parameter_df[PARAMETER_SCALE]))

tests/test_petab.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,11 @@ def test_parameter_properties(petab_problem): # pylint: disable=W0621
557557
assert petab_problem.x_nominal_free_scaled == [7, np.log(8)]
558558
assert petab_problem.x_nominal_fixed_scaled == [np.log10(9)]
559559

560+
# Check that a missing nominalValues column is handled correctly
561+
del petab_problem.parameter_df[NOMINAL_VALUE]
562+
assert len(petab_problem.x_nominal) == 3
563+
assert np.isnan(petab_problem.x_nominal).all()
564+
560565

561566
def test_to_float_if_float():
562567
to_float_if_float = petab.core.to_float_if_float

0 commit comments

Comments
 (0)