diff --git a/autofit/mapper/model_object.py b/autofit/mapper/model_object.py index 3316c7324..9756e51a6 100644 --- a/autofit/mapper/model_object.py +++ b/autofit/mapper/model_object.py @@ -213,7 +213,7 @@ def get_class_path(): loaded_ids=loaded_ids, ) for key, value in d["arguments"].items() - if value + if value is not None } elif type_ == "instance": class_path = get_class_path() diff --git a/test_autofit/serialise/test_samples.py b/test_autofit/serialise/test_samples.py index b3c745247..59e263b8b 100644 --- a/test_autofit/serialise/test_samples.py +++ b/test_autofit/serialise/test_samples.py @@ -157,3 +157,19 @@ def test_generic_from_dict(summary_dict): summary = from_dict(summary_dict) assert isinstance(summary, SamplesSummary) assert isinstance(summary.max_log_likelihood_sample, af.Sample) + + +def test_sample_zero_valued_kwargs_round_trip(): + """ + Sample kwargs whose value is exactly 0.0 (e.g. a prior-median centre) must + survive to_dict -> from_dict — the dict branch previously filtered falsy + values, silently dropping them. + """ + sample = af.Sample( + log_likelihood=1.0, + log_prior=0.0, + weight=1.0, + kwargs={"centre.centre_0": 0.0, "sigma": 6.0}, + ) + loaded = from_dict(to_dict(sample)) + assert loaded.kwargs == {("centre", "centre_0"): 0.0, ("sigma",): 6.0}