Skip to content

Commit

Permalink
Handle missing nominalValue in Problem.get_x_nominal (#223)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dweindl committed Sep 17, 2023
1 parent 304f953 commit 49c672a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion petab/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import os
import tempfile
from math import nan
from pathlib import Path, PurePosixPath
from typing import Dict, Iterable, List, Optional, Union, TYPE_CHECKING
from urllib.parse import unquote, urlparse, urlunparse
Expand Down Expand Up @@ -660,7 +661,11 @@ def get_x_nominal(self, free: bool = True, fixed: bool = True,
-------
The parameter nominal values.
"""
v = list(self.parameter_df[NOMINAL_VALUE])
if NOMINAL_VALUE in self.parameter_df:
v = list(self.parameter_df[NOMINAL_VALUE])
else:
v = [nan] * len(self.parameter_df)

if scaled:
v = list(parameters.map_scale(
v, self.parameter_df[PARAMETER_SCALE]))
Expand Down
5 changes: 5 additions & 0 deletions tests/test_petab.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,11 @@ def test_parameter_properties(petab_problem): # pylint: disable=W0621
assert petab_problem.x_nominal_free_scaled == [7, np.log(8)]
assert petab_problem.x_nominal_fixed_scaled == [np.log10(9)]

# Check that a missing nominalValues column is handled correctly
del petab_problem.parameter_df[NOMINAL_VALUE]
assert len(petab_problem.x_nominal) == 3
assert np.isnan(petab_problem.x_nominal).all()


def test_to_float_if_float():
to_float_if_float = petab.core.to_float_if_float
Expand Down

0 comments on commit 49c672a

Please sign in to comment.