|
25 | 25 |
|
26 | 26 | from ..v1.lint import is_valid_identifier |
27 | 27 | from ..v1.math import sympify_petab |
28 | | -from . import C |
| 28 | +from . import C, get_observable_df |
29 | 29 |
|
30 | 30 | __all__ = [ |
31 | 31 | "Observable", |
@@ -170,7 +170,7 @@ class Observable(BaseModel): |
170 | 170 |
|
171 | 171 | #: :meta private: |
172 | 172 | model_config = ConfigDict( |
173 | | - arbitrary_types_allowed=True, populate_by_name=True |
| 173 | + arbitrary_types_allowed=True, populate_by_name=True, extra="allow" |
174 | 174 | ) |
175 | 175 |
|
176 | 176 | @field_validator( |
@@ -244,6 +244,7 @@ def from_df(cls, df: pd.DataFrame) -> ObservablesTable: |
244 | 244 | if df is None: |
245 | 245 | return cls(observables=[]) |
246 | 246 |
|
| 247 | + df = get_observable_df(df) |
247 | 248 | observables = [ |
248 | 249 | Observable(**row.to_dict()) |
249 | 250 | for _, row in df.reset_index().iterrows() |
@@ -326,6 +327,7 @@ class Change(BaseModel): |
326 | 327 | arbitrary_types_allowed=True, |
327 | 328 | populate_by_name=True, |
328 | 329 | use_enum_values=True, |
| 330 | + extra="allow", |
329 | 331 | ) |
330 | 332 |
|
331 | 333 | @field_validator("target_value", mode="before") |
@@ -367,7 +369,7 @@ class Condition(BaseModel): |
367 | 369 | changes: list[Change] |
368 | 370 |
|
369 | 371 | #: :meta private: |
370 | | - model_config = ConfigDict(populate_by_name=True) |
| 372 | + model_config = ConfigDict(populate_by_name=True, extra="allow") |
371 | 373 |
|
372 | 374 | def __add__(self, other: Change) -> Condition: |
373 | 375 | """Add a change to the set.""" |
@@ -403,7 +405,7 @@ def from_df(cls, df: pd.DataFrame) -> ConditionsTable: |
403 | 405 | return cls(conditions=[]) |
404 | 406 |
|
405 | 407 | 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): |
407 | 409 | changes = [Change(**row) for row in sub_df.to_dict("records")] |
408 | 410 | conditions.append(Condition(id=condition_id, changes=changes)) |
409 | 411 |
|
@@ -468,7 +470,7 @@ class ExperimentPeriod(BaseModel): |
468 | 470 | condition_id: str | None = Field(alias=C.CONDITION_ID, default=None) |
469 | 471 |
|
470 | 472 | #: :meta private: |
471 | | - model_config = ConfigDict(populate_by_name=True) |
| 473 | + model_config = ConfigDict(populate_by_name=True, extra="allow") |
472 | 474 |
|
473 | 475 | @field_validator("condition_id", mode="before") |
474 | 476 | @classmethod |
@@ -497,7 +499,7 @@ class Experiment(BaseModel): |
497 | 499 |
|
498 | 500 | #: :meta private: |
499 | 501 | model_config = ConfigDict( |
500 | | - arbitrary_types_allowed=True, populate_by_name=True |
| 502 | + arbitrary_types_allowed=True, populate_by_name=True, extra="allow" |
501 | 503 | ) |
502 | 504 |
|
503 | 505 | def __add__(self, other: ExperimentPeriod) -> Experiment: |
@@ -614,7 +616,7 @@ class Measurement(BaseModel): |
614 | 616 |
|
615 | 617 | #: :meta private: |
616 | 618 | model_config = ConfigDict( |
617 | | - arbitrary_types_allowed=True, populate_by_name=True |
| 619 | + arbitrary_types_allowed=True, populate_by_name=True, extra="allow" |
618 | 620 | ) |
619 | 621 |
|
620 | 622 | @field_validator( |
@@ -738,7 +740,7 @@ class Mapping(BaseModel): |
738 | 740 | ) |
739 | 741 |
|
740 | 742 | #: :meta private: |
741 | | - model_config = ConfigDict(populate_by_name=True) |
| 743 | + model_config = ConfigDict(populate_by_name=True, extra="allow") |
742 | 744 |
|
743 | 745 |
|
744 | 746 | class MappingTable(BaseModel): |
@@ -831,6 +833,7 @@ class Parameter(BaseModel): |
831 | 833 | arbitrary_types_allowed=True, |
832 | 834 | populate_by_name=True, |
833 | 835 | use_enum_values=True, |
| 836 | + extra="allow", |
834 | 837 | ) |
835 | 838 |
|
836 | 839 | @field_validator("id") |
|
0 commit comments