Skip to content

Commit f32149d

Browse files
authored
Minor improvement in v1 to v2 converter (#479)
* add Warning when removing `PARAMETER_SCALE`, `INITIALIZATION_PRIOR_TYPE`, `INITIALIZATION_PRIOR_PARAMETERS` * Use the experiments table column order that is suggested in the PEtab format * Fix description and redundancy in v2 `get_experiment_df`
1 parent f8ba6b6 commit f32149d

4 files changed

Lines changed: 30 additions & 6 deletions

File tree

petab/v2/experiments.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,14 @@ def get_experiment_df(
1111
experiments_file: str | pd.DataFrame | Path | None,
1212
) -> pd.DataFrame | None:
1313
"""
14-
Read the provided observable file into a ``pandas.Dataframe``.
14+
Read the provided experiments file into a ``pandas.Dataframe``.
1515
1616
Arguments:
1717
experiments_file: Name of the file to read from or pandas.Dataframe.
1818
1919
Returns:
20-
Observable DataFrame
20+
Experiments DataFrame
2121
"""
22-
if experiments_file is None:
23-
return experiments_file
2422

2523
if isinstance(experiments_file, str | Path):
2624
experiments_file = pd.read_csv(

petab/v2/petab1to2.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,15 @@ def create_experiment_id(sim_cond_id: str, preeq_cond_id: str) -> str:
178178
experiments.append(
179179
{
180180
v2.C.EXPERIMENT_ID: exp_id,
181-
v2.C.CONDITION_ID: preeq_cond_id,
182181
v2.C.TIME: v2.C.TIME_PREEQUILIBRATION,
182+
v2.C.CONDITION_ID: preeq_cond_id,
183183
}
184184
)
185185
experiments.append(
186186
{
187187
v2.C.EXPERIMENT_ID: exp_id,
188-
v2.C.CONDITION_ID: sim_cond_id,
189188
v2.C.TIME: 0,
189+
v2.C.CONDITION_ID: sim_cond_id,
190190
}
191191
)
192192
if experiments:
@@ -523,6 +523,19 @@ def update_prior(row):
523523
errors="ignore",
524524
)
525525
# some columns were dropped in PEtab v2
526+
if v1.C.INITIALIZATION_PRIOR_TYPE in df and (
527+
df[v1.C.INITIALIZATION_PRIOR_TYPE].notna().any()
528+
):
529+
warnings.warn(
530+
"Initialisation priors in parameter table are not supported "
531+
"in PEtab v2.",
532+
stacklevel=9,
533+
)
534+
if not (df[v1.C.PARAMETER_SCALE] == v1.C.LIN).all():
535+
warnings.warn(
536+
"Parameter scales are not supported in PEtab v2.",
537+
stacklevel=9,
538+
)
526539
df.drop(
527540
columns=[
528541
v1.C.INITIALIZATION_PRIOR_TYPE,

tests/v2/test_conversion.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ def test_petab1to2_remote():
3333
@pytest.mark.filterwarnings(
3434
"ignore:.*Using `log-normal` instead.*:UserWarning"
3535
)
36+
@pytest.mark.filterwarnings(
37+
"ignore:.*Initialisation priors in parameter table are not supported.*:"
38+
"UserWarning"
39+
)
40+
@pytest.mark.filterwarnings(
41+
"ignore:.*Parameter scales are not supported in PEtab v2.*:UserWarning"
42+
)
3643
@parametrize_or_skip
3744
def test_benchmark_collection(problem_id):
3845
"""Test that we can upgrade all benchmark collection models."""

tests/v2/test_core.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ def test_observable_table_round_trip():
4747
assert observables == observables2
4848

4949

50+
@pytest.mark.filterwarnings(
51+
"ignore:.*Parameter scales are not supported in PEtab v2.*:UserWarning"
52+
)
5053
def test_condition_table_round_trip():
5154
with tempfile.TemporaryDirectory() as tmp_dir:
5255
petab1to2(example_dir_fujita / "Fujita.yaml", tmp_dir)
@@ -59,6 +62,9 @@ def test_condition_table_round_trip():
5962
assert conditions == conditions2
6063

6164

65+
@pytest.mark.filterwarnings(
66+
"ignore:.*Parameter scales are not supported in PEtab v2.*:UserWarning"
67+
)
6268
def test_assert_valid():
6369
problem = petab1to2(example_dir_fujita / "Fujita.yaml")
6470
problem.assert_valid()

0 commit comments

Comments
 (0)