diff --git a/bilby/core/result.py b/bilby/core/result.py index d967138c77ba014af15f5ebc26e6338b6afcaafb..db69507ab571dd7601838f3ee58fd31ef95f599f 100644 --- a/bilby/core/result.py +++ b/bilby/core/result.py @@ -358,10 +358,25 @@ class Result(object): if os.path.isfile(filename): dictionary = deepdish.io.load(filename) - # Some versions of deepdish/pytables return the dictionanary as + # Some versions of deepdish/pytables return the dictionary as # a dictionary with a key 'data' if len(dictionary) == 1 and 'data' in dictionary: dictionary = dictionary['data'] + + if "priors" in dictionary: + # parse priors from JSON string (allowing for backwards + # compatibility) + if not isinstance(dictionary["priors"], PriorDict): + try: + dictionary["priors"] = PriorDict._get_from_json_dict( + dictionary["priors"] + ) + except Exception as e: + raise IOError( + "Unable to parse priors from '{}':\n{}".format( + filename, e, + ) + ) try: if isinstance(dictionary.get('posterior', None), dict): dictionary['posterior'] = pd.DataFrame(dictionary['posterior']) @@ -609,8 +624,9 @@ class Result(object): dictionary['sampler_kwargs'][key] = str(dictionary['sampler_kwargs']) try: + # convert priors to JSON dictionary for both JSON and hdf5 files + dictionary["priors"] = dictionary["priors"]._get_json_dict() if extension == 'json': - dictionary["priors"] = dictionary["priors"]._get_json_dict() if gzip: import gzip # encode to a string