Skip to content

Commit

Permalink
Fixed some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
frode-aarstad committed Nov 30, 2023
1 parent e50d1fa commit ec815b6
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 13 deletions.
4 changes: 4 additions & 0 deletions src/ert/analysis/_es_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,10 @@ def _get_obs_and_measure_data(
}
observation = observation.sel(sub_selection)
ds = source_fs.load_responses(group, tuple(iens_active_index))

if "time" in observation.coords:
observation.coords["time"]= [t[:-3] for t in observation.coords["time"].values.astype(str)]

try:
filtered_ds = observation.merge(ds, join="left")
except KeyError as e:
Expand Down
4 changes: 1 addition & 3 deletions src/ert/config/summary_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,10 @@ 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]
time_map = [datetime.isoformat(t, timespec="microseconds") for t in time_map]
ds = xr.Dataset(
{"values": (["name", "time"], data)},
coords={"time": time_map, "name": keys},
)



return ds.drop_duplicates("time")
6 changes: 6 additions & 0 deletions src/ert/data/_measured_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ def _get_data(
raise ResponseError(_msg)
except KeyError as e:
raise ResponseError(_msg) from e

if "time" in obs.coords:
obs.coords["time"]= [t[:-3] for t in obs.coords["time"].values.astype(str)]

ds = obs.merge(
response,
join="left",
Expand Down Expand Up @@ -205,6 +209,8 @@ def _create_condition(
conditions = []
for obs_key, index_list in zip(obs_keys, index_lists):
if index_list is not None:
if isinstance(index_list[0], datetime):
index_list= [datetime.isoformat(t, timespec="microseconds") for t in index_list]
index_cond = [data_index == index for index in index_list]
index_cond = np.logical_or.reduce(index_cond)
conditions.append(np.logical_and(index_cond, (names == obs_key)))

Check failure on line 216 in src/ert/data/_measured_data.py

View workflow job for this annotation

GitHub Actions / type-checking (3.11)

List comprehension has incompatible type List[str]; expected List[int | datetime]

Check failure on line 216 in src/ert/data/_measured_data.py

View workflow job for this annotation

GitHub Actions / type-checking (3.11)

Argument 1 to "isoformat" of "datetime" has incompatible type "int | datetime"; expected "datetime"
Expand Down
5 changes: 5 additions & 0 deletions src/ert/libres_facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,11 @@ def load_all_summary_data(
df.index = df.index.rename(
{"time": "Date", "realization": "Realization"}
).reorder_levels(["Realization", "Date"])

# remove time part



if keys:
summary_keys = sorted(
[key for key in keys if key in summary_keys]
Expand Down
7 changes: 0 additions & 7 deletions src/ert/storage/local_ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,6 @@ 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"]
#]
#assert ds.coords["time"].data.dtype == np.dtype('datetime64[ns]')

loaded.append(ds)
response = xr.combine_nested(loaded, concat_dim="realization")

Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/unit_tests/data/test_integration_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_summary_obs(create_measured_data):
# Only one observation, we check the key_index is what we expect:
assert summary_obs.data.columns.get_level_values("key_index").values[
0
] == np.datetime64("2011-12-21")
] == "2011-12-21T00:00:00.000000"


@pytest.mark.filterwarnings("ignore::ert.config.ConfigWarning")
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/test_load_forward_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def test_datetime_2500():
facade.load_from_forward_model(ensemble, realizations, 0)

dataset= ensemble.load_responses("summary", tuple([0]))
assert dataset.coords["time"].data.dtype == np.dtype('datetime64[ns]')
assert dataset.coords["time"].data.dtype == np.dtype('object')


@pytest.mark.usefixtures("copy_snake_oil_case_storage")
Expand Down

0 comments on commit ec815b6

Please sign in to comment.