From b713264d52c81b06addc337a357deda571857d2c Mon Sep 17 00:00:00 2001 From: Richard Date: Mon, 13 Feb 2023 10:09:44 +0000 Subject: [PATCH] fix handling deeper attributes in interpolation --- autofit/mapper/model_object.py | 2 +- test_autofit/test_interpolator.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/autofit/mapper/model_object.py b/autofit/mapper/model_object.py index 19b01e116..efd7806cb 100644 --- a/autofit/mapper/model_object.py +++ b/autofit/mapper/model_object.py @@ -48,7 +48,7 @@ def replacing_for_path(self, path: Tuple[str, ...], value) -> "ModelObject": new = copy.deepcopy(self) obj = new for key in path[:-1]: - obj = getattr(new, key) + obj = getattr(obj, key) setattr(obj, path[-1], value) return new diff --git a/test_autofit/test_interpolator.py b/test_autofit/test_interpolator.py index 2e0de50bd..94766e0bd 100644 --- a/test_autofit/test_interpolator.py +++ b/test_autofit/test_interpolator.py @@ -53,3 +53,24 @@ def test_alternate_attribute(time_series, sigma): assert result.gaussian.sigma == sigma assert result.t == -sigma assert result.gaussian.normalization == -sigma + + +def test_deeper_attributes(): + collection = af.Collection( + model=af.Model(af.Gaussian, centre=0.0, normalization=1.0, sigma=-1.0,) + ) + + instance_1 = af.Collection( + t=1.0, collection=collection, + ).instance_from_prior_medians() + instance_2 = af.Collection( + t=2.0, collection=collection, + ).instance_from_prior_medians() + + time_series = af.LinearInterpolator([instance_1, instance_2]) + + result = time_series[time_series.t == 1.5] + + assert result.collection.model.centre == 0.0 + assert result.collection.model.normalization == 1.0 + assert result.collection.model.sigma == -1.0