Skip to content

Commit f4a79eb

Browse files
committed
getitem
1 parent cb78310 commit f4a79eb

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

petab/v2/core.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ class ObservablesTable(BaseModel):
9898

9999
observables: list[Observable]
100100

101+
def __getitem__(self, observable_id: str) -> Observable:
102+
"""Get an observable by ID."""
103+
for observable in self.observables:
104+
if observable.id == observable_id:
105+
return observable
106+
raise KeyError(f"Observable ID {observable_id} not found")
107+
101108
@classmethod
102109
def from_dataframe(cls, df: pd.DataFrame) -> ObservablesTable:
103110
if df is None:
@@ -200,6 +207,13 @@ class ConditionsTable(BaseModel):
200207

201208
conditions: list[ChangeSet]
202209

210+
def __getitem__(self, condition_id: str) -> ChangeSet:
211+
"""Get a condition by ID."""
212+
for condition in self.conditions:
213+
if condition.id == condition_id:
214+
return condition
215+
raise KeyError(f"Condition ID {condition_id} not found")
216+
203217
@classmethod
204218
def from_dataframe(cls, df: pd.DataFrame) -> ConditionsTable:
205219
if df is None:

0 commit comments

Comments
 (0)