Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions ORBIT/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def load_config(filepath):


def prepare_config_for_save(config: dict | benedict) -> dict:
"""Prepare the configuration file for compatbility with the YAML
"""Prepare the configuration file for compatibility with the YAML
``SafeDump`` class used for saving configurations to file.

Parameters
Expand All @@ -47,6 +47,7 @@ def prepare_config_for_save(config: dict | benedict) -> dict:
ORBIT configuration dictionary where all NumPy data types are converted
to standard Python data types, e.g. ``np.float64`` -> ``float``.
"""
config = dict(config)
for k, v in config.items():
match v:
case np.ndarray():
Expand All @@ -56,7 +57,7 @@ def prepare_config_for_save(config: dict | benedict) -> dict:
case np.integer():
config[k] = int(v)
case benedict():
config[k] = prepare_config_for_save(v.dict())
config[k] = prepare_config_for_save(dict(v))
case dict():
config[k] = prepare_config_for_save(v)
case _:
Expand Down Expand Up @@ -90,8 +91,6 @@ def save_config(
raise FileExistsError(f"File already exists at '{filepath}'.")

config = prepare_config_for_save(config)
if isinstance(config, benedict):
config = config.dict()

with filepath.open("w") as f:
yaml.dump(config, f, Dumper=Dumper, default_flow_style=False)
Loading