Skip to content

Commit

Permalink
✨ Added missing_parameter_value_labels property to ParameterGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
s-weigand committed May 20, 2022
1 parent a051427 commit aa17bf0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
15 changes: 15 additions & 0 deletions glotaran/parameter/parameter_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,21 @@ def update_parameter_expression(self):
)
parameter.value = value

@property
def missing_parameter_value_labels(self) -> list[str]:
"""List of full labels where the value is a NaN.
This property is used to validate that all parameters have starting values.
Returns
-------
str
List full labels with missing value.
"""
parameter_df = self.to_dataframe(as_optimized=False)
parameter_nan_value_mask = parameter_df["value"].isna()
return parameter_df[parameter_nan_value_mask]["label"].to_list()

def markdown(self, float_format: str = ".3e") -> MarkdownStr:
"""Format the :class:`ParameterGroup` as markdown string.
Expand Down
24 changes: 24 additions & 0 deletions glotaran/parameter/test/test_parameter_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,3 +342,27 @@ def test_parameter_group_to_from_df():
assert got.non_negative == wanted.non_negative
assert got.value == wanted.value
assert got.vary == wanted.vary


def test_missing_parameter_value_labels():
"""Full labels of all parameters with missing values (NaN) get listed."""
parameter_group = load_parameters(
dedent(
"""\
b:
- ["missing_value_1",]
- ["missing_value_2"]
- ["2", 0.75]
kinetic:
j:
- ["missing_value_3"]
"""
),
format_name="yml_str",
)

assert parameter_group.missing_parameter_value_labels == [
"b.missing_value_1",
"b.missing_value_2",
"kinetic.j.missing_value_3",
]

0 comments on commit aa17bf0

Please sign in to comment.