Skip to content

Commit

Permalink
🩹 ParameterGroup.get degrades full_label of nested Parameters with ne…
Browse files Browse the repository at this point in the history
…sting over 2 (#1043)

* 🧪 Added failing test for issue 933

* 🩹 Fixed issue in ParameterGroup.get with degraded full_label

* 🧪 Added unitest for ParameterGroup.get and label nesting of 3

* 🚧📚 Added change to changelog
  • Loading branch information
s-weigand authored Apr 2, 2022
1 parent acc21fc commit d1a9637
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
### 🩹 Bug fixes

- 🩹 Fix Crash in optimization_group_calculator_linked when using guidance spectra (#950)
- 🩹 ParameterGroup.get degrades full_label of nested Parameters with nesting over 2 (#1043)

### 📚 Documentation

Expand Down
8 changes: 5 additions & 3 deletions glotaran/parameter/parameter_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,9 @@ def get(self, label: str) -> Parameter: # type:ignore[override]
Raised if no parameter with the given label exists.
"""
# sometimes the spec parser delivers the labels as int
label = str(label) # sourcery skip
full_label = str(label) # sourcery skip

path = label.split(".")
path = full_label.split(".")
label = path.pop()

# TODO: audit this code
Expand All @@ -447,7 +447,9 @@ def get(self, label: str) -> Parameter: # type:ignore[override]
except KeyError:
raise ParameterNotFoundException(path, label)
try:
return group._parameters[label]
parameter = group._parameters[label]
parameter.full_label = full_label
return parameter
except KeyError:
raise ParameterNotFoundException(path, label)

Expand Down
2 changes: 2 additions & 0 deletions glotaran/parameter/test/test_parameter_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ def test_parameter_group_from_dict_nested():
assert [p.label for _, p in group.all()] == [f"{i}" for i in range(1, 4)]
assert [p.value for _, p in group.all()] == list(range(7, 10))

assert params.get("kinetic.j.1").full_label == "kinetic.j.1"


def test_parameter_group_to_array():
params = """
Expand Down
17 changes: 17 additions & 0 deletions glotaran/project/test/test_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
from glotaran.io import SAVING_OPTIONS_MINIMAL
from glotaran.io import SavingOptions
from glotaran.project.result import Result
from glotaran.project.scheme import Scheme
from glotaran.testing.simulated_data.sequential_spectral_decay import DATASET
from glotaran.testing.simulated_data.sequential_spectral_decay import SCHEME
from glotaran.testing.simulated_data.sequential_spectral_decay import SIMULATION_MODEL
from glotaran.testing.simulated_data.shared_decay import SIMULATION_PARAMETERS
from glotaran.testing.simulated_data.shared_decay import SPECTRAL_AXIS


Expand All @@ -37,6 +41,19 @@ def test_result_ipython_rendering(dummy_result: Result):
assert rendered_markdown_return["text/markdown"].startswith("| Optimization Result")


def test_result_markdown_nested_parameters():
"""Test not crash of Result.markdown() for nested parameters
See https://github.com/glotaran/pyglotaran/issues/933
"""
scheme = Scheme(
model=SIMULATION_MODEL, parameters=SIMULATION_PARAMETERS, data={"dataset_1": DATASET}
)
result = optimize(scheme, raise_exception=True)

assert "shapes.species_1.amplitude" in result.markdown()


def test_get_scheme(dummy_result: Result):
scheme = dummy_result.get_scheme()
assert "residual" not in dummy_result.scheme.data["dataset_1"]
Expand Down

0 comments on commit d1a9637

Please sign in to comment.