Skip to content

Commit 9ba7fa2

Browse files
committed
valueType/operationType
1 parent 1bdb36f commit 9ba7fa2

File tree

5 files changed

+23
-32
lines changed

5 files changed

+23
-32
lines changed

petab/v2/C.py

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

152145
CONDITION_DF_COLS = [
153146
CONDITION_ID,
154147
TARGET_ID,
155-
VALUE_TYPE,
148+
OPERATION_TYPE,
156149
TARGET_VALUE,
157150
]
158151

petab/v2/core.py

Lines changed: 3 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,8 @@ 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 data.get(C.OPERATION_TYPE) != C.OT_NO_CHANGE:
246+
target_id = data.get(C.TARGET_ID)
247247

248248
if not is_valid_identifier(target_id):
249249
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
@@ -300,7 +300,7 @@ def v1v2_condition_df(
300300
columns=[
301301
v2.C.CONDITION_ID,
302302
v2.C.TARGET_ID,
303-
v2.C.VALUE_TYPE,
303+
v2.C.OPERATION_TYPE,
304304
v2.C.TARGET_VALUE,
305305
]
306306
)
@@ -319,7 +319,5 @@ def v1v2_condition_df(
319319
f"Unable to determine value type {target} in the condition "
320320
"table."
321321
)
322-
condition_df[v2.C.VALUE_TYPE] = condition_df[v2.C.TARGET_ID].apply(
323-
lambda x: v2.C.VT_INITIAL if x in initial else v2.C.VT_CONSTANT
324-
)
322+
condition_df[v2.C.OPERATION_TYPE] = v2.C.OT_CUR_VAL
325323
return condition_df

petab/v2/problem.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -795,10 +795,10 @@ def add_condition(
795795
{
796796
CONDITION_ID: id_,
797797
TARGET_ID: target_id,
798-
VALUE_TYPE: value_type,
798+
OPERATION_TYPE: op_type,
799799
TARGET_VALUE: target_value,
800800
}
801-
for target_id, (value_type, target_value) in kwargs.items()
801+
for target_id, (op_type, target_value) in kwargs.items()
802802
]
803803
# TODO: is the condition name supported in v2?
804804
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)