diff --git a/autofit/non_linear/samples/util.py b/autofit/non_linear/samples/util.py index 8c53fad09..f5df1bdad 100644 --- a/autofit/non_linear/samples/util.py +++ b/autofit/non_linear/samples/util.py @@ -11,7 +11,7 @@ def simple_model_for_kwargs(kwargs: Dict[Union[str, Tuple[str, ...]], float]): path = (path,) component = model if len(path) > 1: - for part in path[:1]: + for part in path[:-1]: try: component = component[part] except KeyError: diff --git a/test_autofit/non_linear/samples/test_simple_model_for_kwargs.py b/test_autofit/non_linear/samples/test_simple_model_for_kwargs.py new file mode 100644 index 000000000..f38a09860 --- /dev/null +++ b/test_autofit/non_linear/samples/test_simple_model_for_kwargs.py @@ -0,0 +1,13 @@ +from autofit.non_linear.samples.util import simple_model_for_kwargs + + +def test_path_regression(): + kwargs = { + ("galaxies", "lens", "shear", "angle"): 1.0, + ("galaxies", "lens", "shear", "magnitude"): 2.0, + } + model = simple_model_for_kwargs(kwargs) + + shear = model.galaxies.lens.shear + assert shear.angle.mean == 1.0 + assert shear.magnitude.mean == 2.0