Skip to content

Commit 35e4098

Browse files
committed
valueType/operationType
1 parent 10502bd commit 35e4098

File tree

5 files changed

+26
-32
lines changed

5 files changed

+26
-32
lines changed

petab/v2/C.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -130,30 +130,23 @@
130130
CONDITION_NAME = "conditionName"
131131
#: Column in the condition table with the ID of an entity that is changed
132132
TARGET_ID = "targetId"
133-
#: Column in the condition table with the type of value that is changed
134-
VALUE_TYPE = "valueType"
133+
#: Column in the condition table with the operation type
134+
OPERATION_TYPE = "operationType"
135135
#: Column in the condition table with the new value of the target entity
136136
TARGET_VALUE = "targetValue"
137-
# value types:
138-
VT_CONSTANT = "constant"
139-
VT_INITIAL = "initial"
140-
VT_RATE = "rate"
141-
VT_ASSIGNMENT = "assignment"
142-
VT_RELATIVE_RATE = "relativeRate"
143-
VT_RELATIVE_ASSIGNMENT = "relativeAssignment"
144-
VALUE_TYPES = [
145-
VT_CONSTANT,
146-
VT_INITIAL,
147-
VT_RATE,
148-
VT_ASSIGNMENT,
149-
VT_RELATIVE_RATE,
150-
VT_RELATIVE_ASSIGNMENT,
137+
# opeartion types:
138+
OT_CUR_VAL = "setCurrentValue"
139+
OT_NO_CHANGE = "noChange"
140+
141+
OPERATION_TYPES = [
142+
OT_CUR_VAL,
143+
OT_NO_CHANGE,
151144
]
152145

153146
CONDITION_DF_COLS = [
154147
CONDITION_ID,
155148
TARGET_ID,
156-
VALUE_TYPE,
149+
OPERATION_TYPE,
157150
TARGET_VALUE,
158151
]
159152

petab/v2/core.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ class Change(BaseModel):
231231
"""
232232

233233
target_id: str | None = Field(alias=C.TARGET_ID, default=None)
234-
operation_type: OperationType = Field(alias=C.VALUE_TYPE)
234+
operation_type: OperationType = Field(alias=C.OPERATION_TYPE)
235235
target_value: sp.Basic | None = Field(alias=C.TARGET_VALUE, default=None)
236236

237237
class Config:
@@ -242,8 +242,11 @@ class Config:
242242
@model_validator(mode="before")
243243
@classmethod
244244
def validate_id(cls, data: dict):
245-
if data.get("operation_type") != OperationType.NO_CHANGE:
246-
target_id = data.get("target_id")
245+
if (
246+
data.get("operation_type", data.get(C.OPERATION_TYPE))
247+
!= C.OT_NO_CHANGE
248+
):
249+
target_id = data.get("target_id", data.get(C.TARGET_ID))
247250

248251
if not is_valid_identifier(target_id):
249252
raise ValueError(f"Invalid ID: {target_id}")

petab/v2/petab1to2.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ def v1v2_condition_df(
301301
columns=[
302302
v2.C.CONDITION_ID,
303303
v2.C.TARGET_ID,
304-
v2.C.VALUE_TYPE,
304+
v2.C.OPERATION_TYPE,
305305
v2.C.TARGET_VALUE,
306306
]
307307
)
@@ -320,7 +320,5 @@ def v1v2_condition_df(
320320
f"Unable to determine value type {target} in the condition "
321321
"table."
322322
)
323-
condition_df[v2.C.VALUE_TYPE] = condition_df[v2.C.TARGET_ID].apply(
324-
lambda x: v2.C.VT_INITIAL if x in initial else v2.C.VT_CONSTANT
325-
)
323+
condition_df[v2.C.OPERATION_TYPE] = v2.C.OT_CUR_VAL
326324
return condition_df

petab/v2/problem.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -796,10 +796,10 @@ def add_condition(
796796
{
797797
CONDITION_ID: id_,
798798
TARGET_ID: target_id,
799-
VALUE_TYPE: value_type,
799+
OPERATION_TYPE: op_type,
800800
TARGET_VALUE: target_value,
801801
}
802-
for target_id, (value_type, target_value) in kwargs.items()
802+
for target_id, (op_type, target_value) in kwargs.items()
803803
]
804804
# TODO: is the condition name supported in v2?
805805
if name is not None:

tests/v2/test_problem.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
NOMINAL_VALUE,
1717
OBSERVABLE_FORMULA,
1818
OBSERVABLE_ID,
19+
OPERATION_TYPE,
20+
OT_CUR_VAL,
1921
PARAMETER_ID,
2022
PETAB_ENTITY_ID,
2123
TARGET_ID,
2224
TARGET_VALUE,
2325
UPPER_BOUND,
24-
VALUE_TYPE,
25-
VT_CONSTANT,
2626
)
2727

2828

@@ -73,7 +73,7 @@ def test_problem_from_yaml_multiple_files():
7373

7474
for i in (1, 2):
7575
problem = Problem()
76-
problem.add_condition(f"condition{i}", parameter1=(VT_CONSTANT, i))
76+
problem.add_condition(f"condition{i}", parameter1=(OT_CUR_VAL, i))
7777
petab.write_condition_df(
7878
problem.condition_df, Path(tmpdir, f"conditions{i}.tsv")
7979
)
@@ -109,14 +109,14 @@ def test_problem_from_yaml_multiple_files():
109109
def test_modify_problem():
110110
"""Test modifying a problem via the API."""
111111
problem = Problem()
112-
problem.add_condition("condition1", parameter1=(VT_CONSTANT, 1))
113-
problem.add_condition("condition2", parameter2=(VT_CONSTANT, 2))
112+
problem.add_condition("condition1", parameter1=(OT_CUR_VAL, 1))
113+
problem.add_condition("condition2", parameter2=(OT_CUR_VAL, 2))
114114

115115
exp_condition_df = pd.DataFrame(
116116
data={
117117
CONDITION_ID: ["condition1", "condition2"],
118118
TARGET_ID: ["parameter1", "parameter2"],
119-
VALUE_TYPE: [VT_CONSTANT, VT_CONSTANT],
119+
OPERATION_TYPE: [OT_CUR_VAL, OT_CUR_VAL],
120120
TARGET_VALUE: [1.0, 2.0],
121121
}
122122
)

0 commit comments

Comments
 (0)