diff --git a/src/ert/config/gen_kw_config.py b/src/ert/config/gen_kw_config.py index e7b9124d22c..0565f53ff96 100644 --- a/src/ert/config/gen_kw_config.py +++ b/src/ert/config/gen_kw_config.py @@ -332,8 +332,23 @@ def write_to_runpath( f" is of size {len(self.transform_functions)}, expected {array.size}" ) + def parse_value(value: float | int | str) -> float | int | str: + if isinstance(value, float | int): + return value + try: + return int(value) + except ValueError: + try: + return float(value) + except ValueError: + return value + data = dict( - zip(array["names"].values.tolist(), array.values.tolist(), strict=False) + zip( + array["names"].values.tolist(), + [parse_value(i) for i in array.values], + strict=False, + ) ) log10_data = { @@ -358,7 +373,6 @@ def write_to_runpath( template = template.replace(f"<{key}>", f"{value:.6g}") with open(run_path / target_file, "w", encoding="utf-8") as f: f.write(template) - if log10_data: return {self.name: data, f"LOG10_{self.name}": log10_data} else: diff --git a/src/ert/enkf_main.py b/src/ert/enkf_main.py index 78b04a9e7f2..73114a7c8e9 100644 --- a/src/ert/enkf_main.py +++ b/src/ert/enkf_main.py @@ -65,24 +65,9 @@ def _value_export_json( if len(values) == 0: return - def parse_value(value: float | int | str) -> float | int | str: - if isinstance(value, float | int): - return value - try: - return int(value) - except ValueError: - try: - return float(value) - except ValueError: - return value - # Hierarchical - json_out: dict[str, float | dict[str, float | int | str]] = { - key: { - inner_key: parse_value(inner_value) - for inner_key, inner_value in param_map.items() - } - for key, param_map in values.items() + json_out: dict[str, float | dict[str, float]] = { + key: dict(param_map.items()) for key, param_map in values.items() } # Disallow NaN from being written: ERT produces the parameters and the only