diff --git a/src/ert/config/summary_config.py b/src/ert/config/summary_config.py index 1ec0fd1baae..21c314358cd 100644 --- a/src/ert/config/summary_config.py +++ b/src/ert/config/summary_config.py @@ -62,6 +62,7 @@ def read_from_file(self, run_path: str, iens: int) -> xr.Dataset: summary_data.sort(key=lambda x: x[0]) data = [d for _, d in summary_data] keys = [k for k, _ in summary_data] + time_map = [datetime.isoformat(t) for t in time_map] ds = xr.Dataset( {"values": (["name", "time"], data)}, coords={"time": time_map, "name": keys}, diff --git a/src/ert/libres_facade.py b/src/ert/libres_facade.py index a6236dbdeb5..481fdc8a3e7 100644 --- a/src/ert/libres_facade.py +++ b/src/ert/libres_facade.py @@ -411,7 +411,9 @@ def load_all_summary_data( summary_keys = ensemble.get_summary_keyset() try: - df = ensemble.load_responses("summary", tuple(realizations)).to_dataframe() + df = ensemble.load_responses("summary", tuple(realizations)).to_dataframe( + {"time", "name", "realization"} + ) except (ValueError, KeyError): return pd.DataFrame() df = df.unstack(level="name") diff --git a/src/ert/storage/local_ensemble.py b/src/ert/storage/local_ensemble.py index 7a18bc7ee28..11bf74beb0c 100644 --- a/src/ert/storage/local_ensemble.py +++ b/src/ert/storage/local_ensemble.py @@ -217,8 +217,15 @@ def load_responses( if not input_path.exists(): raise KeyError(f"No response for key {key}, realization: {realization}") ds = xr.open_dataset(input_path, engine="scipy") + if "time" in ds.coords: + ds.coords["time"] = [ + datetime.fromisoformat(str(e.values).split(".", maxsplit=1)[0]) + for e in ds.coords["time"] + ] + loaded.append(ds) response = xr.combine_nested(loaded, concat_dim="realization") + assert isinstance(response, xr.Dataset) return response diff --git a/tests/unit_tests/test_load_forward_model.py b/tests/unit_tests/test_load_forward_model.py index 5fa5d779c5d..2465153c235 100644 --- a/tests/unit_tests/test_load_forward_model.py +++ b/tests/unit_tests/test_load_forward_model.py @@ -110,6 +110,38 @@ def test_load_inconsistent_time_map_summary(caplog): assert loaded == 1 +@pytest.mark.usefixtures("copy_snake_oil_case_storage") +def test_datetime_2500(): + """ + Test that we are able to work with dates past year 2263 in summary files. + + """ + cwd = os.getcwd() + + # Get rid of GEN_DATA as we are only interested in SUMMARY + with fileinput.input("snake_oil.ert", inplace=True) as fin: + for line in fin: + if line.startswith("GEN_DATA"): + continue + print(line, end="") + + facade = LibresFacade.from_config_file("snake_oil.ert") + realisation_number = 0 + storage = open_storage(facade.enspath, mode="w") + ensemble = storage.get_ensemble_by_name("default_0") + + # Create a result that is incompatible with the refcase + run_path = Path("storage") / "snake_oil" / "runpath" / "realization-0" / "iter-0" + os.chdir(run_path) + ecl_sum = run_simulator(100, datetime(2500, 1, 1)) + ecl_sum.fwrite() + os.chdir(cwd) + + realizations = [False] * facade.get_ensemble_size() + realizations[realisation_number] = True + facade.load_from_forward_model(ensemble, realizations, 0) + + @pytest.mark.usefixtures("copy_snake_oil_case_storage") def test_load_forward_model(snake_oil_default_storage): """