Skip to content

Commit

Permalink
Merge pull request #240 from PEtab-dev/release_0.2.7
Browse files Browse the repository at this point in the history
Release 0.2.7
  • Loading branch information
dweindl authored Dec 18, 2023
2 parents eb08318 + 432a12b commit c7d93c3
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 14 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

## 0.2 series

### 0.2.7

* Fixed a bug in `flatten_timepoint_specific_output_overrides`, which
did not handle numeric values correctly

**Full Changelog**: https://github.com/PEtab-dev/libpetab-python/compare/v0.2.6...v0.2.7

### 0.2.6

* Fixed `flatten_timepoint_specific_output_overrides` not supporting
Expand Down
5 changes: 5 additions & 0 deletions petab/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import numpy as np
import pandas as pd
from pandas.api.types import is_string_dtype

from . import yaml
from .C import * # noqa: F403
Expand Down Expand Up @@ -282,6 +283,10 @@ def flatten_timepoint_specific_output_overrides(
if field not in measurements:
continue

if not is_string_dtype(type(observable[target])):
# if not a string, we don't have to substitute anything
continue

hyperparameter_replacement_id = get_hyperparameter_replacement_id(
hyperparameter_type=hyperparameter_type,
observable_replacement_id=observable_replacement_id,
Expand Down
2 changes: 1 addition & 1 deletion petab/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""PEtab library version"""
__version__ = "0.2.6"
__version__ = "0.2.7"
49 changes: 36 additions & 13 deletions tests/test_petab.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,12 +349,14 @@ def test_flatten_timepoint_specific_output_overrides():
"""Test flatten_timepoint_specific_output_overrides"""
observable_df = pd.DataFrame(
data={
OBSERVABLE_ID: ["obs1"],
OBSERVABLE_ID: ["obs1", "obs2"],
OBSERVABLE_FORMULA: [
"observableParameter1_obs1 + observableParameter2_obs1"
"observableParameter1_obs1 + observableParameter2_obs1",
"x",
],
NOISE_FORMULA: [
"(observableParameter1_obs1 + observableParameter2_obs1) * noiseParameter1_obs1"
"(observableParameter1_obs1 + observableParameter2_obs1) * noiseParameter1_obs1",
1,
],
}
)
Expand All @@ -366,11 +368,17 @@ def test_flatten_timepoint_specific_output_overrides():
obs1_2_2_1 = "obs1__obsParOverride2_1_0__noiseParOverride2__condition1"
observable_df_expected = pd.DataFrame(
data={
OBSERVABLE_ID: [obs1_1_1_1, obs1_2_1_1, obs1_2_2_1],
OBSERVABLE_ID: [
obs1_1_1_1,
obs1_2_1_1,
obs1_2_2_1,
"obs2__condition1",
],
OBSERVABLE_FORMULA: [
f"observableParameter1_{obs1_1_1_1} + observableParameter2_{obs1_1_1_1}",
f"observableParameter1_{obs1_2_1_1} + observableParameter2_{obs1_2_1_1}",
f"observableParameter1_{obs1_2_2_1} + observableParameter2_{obs1_2_2_1}",
"x",
],
NOISE_FORMULA: [
f"(observableParameter1_{obs1_1_1_1} + observableParameter2_{obs1_1_1_1})"
Expand All @@ -379,6 +387,7 @@ def test_flatten_timepoint_specific_output_overrides():
f" * noiseParameter1_{obs1_2_1_1}",
f"(observableParameter1_{obs1_2_2_1} + observableParameter2_{obs1_2_2_1})"
f" * noiseParameter1_{obs1_2_2_1}",
1,
],
}
)
Expand All @@ -387,54 +396,66 @@ def test_flatten_timepoint_specific_output_overrides():
# Measurement table with timepoint-specific overrides
measurement_df = pd.DataFrame(
data={
OBSERVABLE_ID: ["obs1", "obs1", "obs1", "obs1"],
OBSERVABLE_ID: ["obs1", "obs1", "obs1", "obs1", "obs2"],
SIMULATION_CONDITION_ID: [
"condition1",
"condition1",
"condition1",
"condition1",
"condition1",
],
PREEQUILIBRATION_CONDITION_ID: ["", "", "", ""],
TIME: [1.0, 1.0, 2.0, 2.0],
MEASUREMENT: [0.1] * 4,
PREEQUILIBRATION_CONDITION_ID: ["", "", "", "", ""],
TIME: [1.0, 1.0, 2.0, 2.0, 3.0],
MEASUREMENT: [0.1] * 5,
OBSERVABLE_PARAMETERS: [
"obsParOverride1;1.0",
"obsParOverride2;1.0",
"obsParOverride2;1.0",
"obsParOverride2;1.0",
"",
],
NOISE_PARAMETERS: [
"noiseParOverride1",
"noiseParOverride1",
"noiseParOverride2",
"noiseParOverride2",
"",
],
}
)

measurement_df_expected = pd.DataFrame(
data={
OBSERVABLE_ID: [obs1_1_1_1, obs1_2_1_1, obs1_2_2_1, obs1_2_2_1],
OBSERVABLE_ID: [
obs1_1_1_1,
obs1_2_1_1,
obs1_2_2_1,
obs1_2_2_1,
"obs2__condition1",
],
SIMULATION_CONDITION_ID: [
"condition1",
"condition1",
"condition1",
"condition1",
"condition1",
],
PREEQUILIBRATION_CONDITION_ID: ["", "", "", ""],
TIME: [1.0, 1.0, 2.0, 2.0],
MEASUREMENT: [0.1] * 4,
PREEQUILIBRATION_CONDITION_ID: ["", "", "", "", ""],
TIME: [1.0, 1.0, 2.0, 2.0, 3.0],
MEASUREMENT: [0.1] * 5,
OBSERVABLE_PARAMETERS: [
"obsParOverride1;1.0",
"obsParOverride2;1.0",
"obsParOverride2;1.0",
"obsParOverride2;1.0",
"",
],
NOISE_PARAMETERS: [
"noiseParOverride1",
"noiseParOverride1",
"noiseParOverride2",
"noiseParOverride2",
"",
],
}
)
Expand Down Expand Up @@ -483,7 +504,9 @@ def test_flatten_timepoint_specific_output_overrides():
petab_problem=unflattened_problem,
)
# The unflattened simulation dataframe has the original observable IDs.
assert (unflattened_simulation_df[OBSERVABLE_ID] == "obs1").all()
assert (
unflattened_simulation_df[OBSERVABLE_ID] == ["obs1"] * 4 + ["obs2"]
).all()


def test_flatten_timepoint_specific_output_overrides_special_cases():
Expand Down

0 comments on commit c7d93c3

Please sign in to comment.