Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions petab/v1/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,8 @@ def append_overrides(overrides):
if not model.has_entity_with_id(p):
parameter_ids[p] = None

# remove parameters that occur in the condition table and are overridden
# for ALL conditions
for p in condition_df.columns[~condition_df.isnull().any()]:
# parameters that are overridden via the condition table are not allowed
for p in condition_df.columns:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of try-except, could do one of these, but fine as is

for p in set(condition_df.columns).intersection(parameter_ids):
    del parameter_ids[p]

for p in condition_df.columns:
    if p in parameter_ids:
        del parameter_ids[p]

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but then one has to look up each element twice.

try:
del parameter_ids[p]
except KeyError:
Expand Down
7 changes: 2 additions & 5 deletions petab/v2/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,11 +621,8 @@ def append_overrides(overrides):
if not problem.model.has_entity_with_id(p)
)

# remove parameters that occur in the condition table and are overridden
# for ALL conditions
for p in problem.condition_df.columns[
~problem.condition_df.isnull().any()
]:
# parameters that are overridden via the condition table are not allowed
for p in problem.condition_df.columns:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since parameter IDs is now a set, can change try-except/loop to

parameter_ids -= set(condition_df.columns)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but parameter_ids is still an OrderedDict (we wanted to preserve order here). Only the returned DictKeyView (or similar) acts like a set.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it's right before returning, it could be done just on the keys, but then future modifications might easily mess up the ordering. I'd leave it as is until Python has a proper OrderedSet.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does it become OrderedDict? In the v1 code it's initialized as an OrderedDict, but here as a set?

Copy link
Member Author

@dweindl dweindl Dec 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. I was in v1.
Not sure why I changed it to set there in the first place.

try:
parameter_ids.remove(p)
except KeyError:
Expand Down
8 changes: 6 additions & 2 deletions petab/v2/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from . import experiments

if TYPE_CHECKING:
from ..v2.lint import ValidationIssue, ValidationResultList, ValidationTask
from ..v2.lint import ValidationResultList, ValidationTask


__all__ = ["Problem"]
Expand Down Expand Up @@ -722,7 +722,11 @@ def validate(
Returns:
A list of validation results.
"""
from ..v2.lint import ValidationIssueSeverity, ValidationResultList
from ..v2.lint import (
ValidationIssue,
ValidationIssueSeverity,
ValidationResultList,
)

validation_results = ValidationResultList()
if self.extensions_config:
Expand Down
Loading