Skip to content

Commit adbd5b6

Browse files
committed
Faster ConditionsTable.from_df
1 parent 1649080 commit adbd5b6

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

petab/v1/lint.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@
5353
"observable_table_has_nontrivial_noise_formula",
5454
]
5555

56+
#: Regular expression pattern for valid PEtab IDs
57+
_petab_id_pattern = re.compile(r"^[a-zA-Z_]\w*$")
58+
5659

5760
def _check_df(df: pd.DataFrame, req_cols: Iterable, name: str) -> None:
5861
"""Check if given columns are present in DataFrame
@@ -1189,7 +1192,7 @@ def is_valid_identifier(x: str) -> bool:
11891192
if pd.isna(x):
11901193
return False
11911194

1192-
return re.match(r"^[a-zA-Z_]\w*$", x) is not None
1195+
return _petab_id_pattern.match(x) is not None
11931196

11941197

11951198
def check_ids(ids: Iterable[str], kind: str = "") -> None:

petab/v2/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ def from_df(cls, df: pd.DataFrame) -> ConditionsTable:
404404

405405
conditions = []
406406
for condition_id, sub_df in df.reset_index().groupby(C.CONDITION_ID):
407-
changes = [Change(**row.to_dict()) for _, row in sub_df.iterrows()]
407+
changes = [Change(**row) for row in sub_df.to_dict("records")]
408408
conditions.append(Condition(id=condition_id, changes=changes))
409409

410410
return cls(conditions=conditions)

0 commit comments

Comments
 (0)