Skip to content

Commit cd6cd3e

Browse files
committed
allow extra
1 parent adbd5b6 commit cd6cd3e

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

petab/v2/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
get_observable_df,
2525
write_observable_df,
2626
)
27+
from petab.v1.parameters import ( # noqa: F401, E402
28+
get_parameter_df,
29+
write_parameter_df,
30+
)
2731
from petab.v1.yaml import load_yaml # noqa: F401, E402
2832

2933
# import after v1

petab/v2/core.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
from ..v1.lint import is_valid_identifier
2727
from ..v1.math import sympify_petab
28-
from . import C
28+
from . import C, get_observable_df
2929

3030
__all__ = [
3131
"Observable",
@@ -170,7 +170,7 @@ class Observable(BaseModel):
170170

171171
#: :meta private:
172172
model_config = ConfigDict(
173-
arbitrary_types_allowed=True, populate_by_name=True
173+
arbitrary_types_allowed=True, populate_by_name=True, extra="allow"
174174
)
175175

176176
@field_validator(
@@ -244,6 +244,7 @@ def from_df(cls, df: pd.DataFrame) -> ObservablesTable:
244244
if df is None:
245245
return cls(observables=[])
246246

247+
df = get_observable_df(df)
247248
observables = [
248249
Observable(**row.to_dict())
249250
for _, row in df.reset_index().iterrows()
@@ -326,6 +327,7 @@ class Change(BaseModel):
326327
arbitrary_types_allowed=True,
327328
populate_by_name=True,
328329
use_enum_values=True,
330+
extra="allow",
329331
)
330332

331333
@field_validator("target_value", mode="before")
@@ -367,7 +369,7 @@ class Condition(BaseModel):
367369
changes: list[Change]
368370

369371
#: :meta private:
370-
model_config = ConfigDict(populate_by_name=True)
372+
model_config = ConfigDict(populate_by_name=True, extra="allow")
371373

372374
def __add__(self, other: Change) -> Condition:
373375
"""Add a change to the set."""
@@ -403,7 +405,7 @@ def from_df(cls, df: pd.DataFrame) -> ConditionsTable:
403405
return cls(conditions=[])
404406

405407
conditions = []
406-
for condition_id, sub_df in df.reset_index().groupby(C.CONDITION_ID):
408+
for condition_id, sub_df in df.groupby(C.CONDITION_ID):
407409
changes = [Change(**row) for row in sub_df.to_dict("records")]
408410
conditions.append(Condition(id=condition_id, changes=changes))
409411

@@ -468,7 +470,7 @@ class ExperimentPeriod(BaseModel):
468470
condition_id: str | None = Field(alias=C.CONDITION_ID, default=None)
469471

470472
#: :meta private:
471-
model_config = ConfigDict(populate_by_name=True)
473+
model_config = ConfigDict(populate_by_name=True, extra="allow")
472474

473475
@field_validator("condition_id", mode="before")
474476
@classmethod
@@ -497,7 +499,7 @@ class Experiment(BaseModel):
497499

498500
#: :meta private:
499501
model_config = ConfigDict(
500-
arbitrary_types_allowed=True, populate_by_name=True
502+
arbitrary_types_allowed=True, populate_by_name=True, extra="allow"
501503
)
502504

503505
def __add__(self, other: ExperimentPeriod) -> Experiment:
@@ -614,7 +616,7 @@ class Measurement(BaseModel):
614616

615617
#: :meta private:
616618
model_config = ConfigDict(
617-
arbitrary_types_allowed=True, populate_by_name=True
619+
arbitrary_types_allowed=True, populate_by_name=True, extra="allow"
618620
)
619621

620622
@field_validator(
@@ -738,7 +740,7 @@ class Mapping(BaseModel):
738740
)
739741

740742
#: :meta private:
741-
model_config = ConfigDict(populate_by_name=True)
743+
model_config = ConfigDict(populate_by_name=True, extra="allow")
742744

743745

744746
class MappingTable(BaseModel):
@@ -831,6 +833,7 @@ class Parameter(BaseModel):
831833
arbitrary_types_allowed=True,
832834
populate_by_name=True,
833835
use_enum_values=True,
836+
extra="allow",
834837
)
835838

836839
@field_validator("id")

0 commit comments

Comments
 (0)