Skip to content

Commit

Permalink
Backport: Fix read_from_file error propagation
Browse files Browse the repository at this point in the history
  • Loading branch information
yngve-sk authored and oyvindeide committed Oct 22, 2024
1 parent b5104b6 commit 5717e4d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/ert/config/gen_data_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,11 @@ def _read_file(filename: Path, report_step: int) -> xr.Dataset:
except ValueError as err:
errors.append(str(err))

ds_all_report_steps = xr.concat(
datasets_per_report_step, dim="report_step"
).expand_dims(name=[name])
datasets_per_name.append(ds_all_report_steps)
if len(datasets_per_report_step) > 0:
ds_all_report_steps = xr.concat(
datasets_per_report_step, dim="report_step"
).expand_dims(name=[name])
datasets_per_name.append(ds_all_report_steps)

if errors:
raise ValueError(f"Error reading GEN_DATA: {self.name}, errors: {errors}")
Expand Down
27 changes: 27 additions & 0 deletions tests/unit_tests/config/test_gen_data_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,30 @@ def test_malformed_or_missing_gen_data_result_file(result_file, error_message):
GenDataConfig.from_config_dict({"GEN_DATA": [config_line.split()]})
else:
GenDataConfig.from_config_dict({"GEN_DATA": [config_line.split()]})


def test_that_invalid_gendata_outfile_error_propagates(tmp_path):
(tmp_path / "poly.out").write_text("""
4.910405046410615,4.910405046410615
6.562317389289953,6.562317389289953
9.599763191512997,9.599763191512997
14.022742453079745,14.022742453079745
19.831255173990197,19.831255173990197
27.025301354244355,27.025301354244355
35.604880993842215,35.604880993842215
45.56999409278378,45.56999409278378
56.92064065106905,56.92064065106905
69.65682066869802,69.65682066869802
""")

config = GenDataConfig(
name="gen_data",
keys=["something"],
report_steps_list=[None],
input_files=["poly.out"],
)
with pytest.raises(
ValueError,
match="Error reading GEN_DATA.*could not convert string.*4.910405046410615,4.910405046410615.*to float64",
):
config.read_from_file(tmp_path, 0)

0 comments on commit 5717e4d

Please sign in to comment.