Skip to content

Commit 52e51d5

Browse files
dweindlclaude
andcommitted
Fix missing return in v1v2_observable_df noise distribution merge
update_noise_dist lacked a return statement, so the merged noiseDistribution column was always NaN after petab1to2 conversion. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 parent 2bb8830 commit 52e51d5

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

petab/v2/petab1to2.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,8 @@ def update_noise_dist(row):
416416
f" is not supported in PEtab v2."
417417
)
418418

419+
return new_dist
420+
419421
df[v2.C.NOISE_DISTRIBUTION] = df.apply(update_noise_dist, axis=1)
420422
df.drop(columns=[v1.C.OBSERVABLE_TRANSFORMATION], inplace=True)
421423

tests/v2/test_conversion.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,33 @@
11
import logging
22

3+
import pandas as pd
34
import pytest
45

6+
import petab.v1 as v1
7+
import petab.v2 as v2
58
from petab.v2 import Problem
6-
from petab.v2.petab1to2 import petab1to2
9+
from petab.v2.petab1to2 import petab1to2, v1v2_observable_df
10+
11+
12+
def test_v1v2_observable_df_noise_distribution():
13+
"""Test that noiseDistribution is correctly merged with
14+
observableTransformation."""
15+
observable_df = pd.DataFrame(
16+
data={
17+
v1.C.OBSERVABLE_ID: ["obs1", "obs2"],
18+
v1.C.OBSERVABLE_FORMULA: ["a", "b"],
19+
v1.C.NOISE_FORMULA: ["1", "1"],
20+
v1.C.OBSERVABLE_TRANSFORMATION: [v1.C.LIN, v1.C.LOG],
21+
v1.C.NOISE_DISTRIBUTION: [v1.C.NORMAL, v1.C.NORMAL],
22+
}
23+
).set_index(v1.C.OBSERVABLE_ID)
24+
25+
new_df = v1v2_observable_df(observable_df)
26+
27+
assert list(new_df[v2.C.NOISE_DISTRIBUTION]) == [
28+
v2.C.NORMAL,
29+
v2.C.LOG_NORMAL,
30+
]
731

832

933
def test_petab1to2_remote():

0 commit comments

Comments
 (0)