Skip to content

Commit

Permalink
Fixup keyerror bug w/ missing smry data
Browse files Browse the repository at this point in the history
  • Loading branch information
yngve-sk committed Dec 16, 2024
1 parent 0d10c5d commit 10e712a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ert/dark_storage/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def get_observation_keys_for_response(

elif (
displayed_response_key
in ensemble.experiment.response_type_to_response_keys["summary"]
in ensemble.experiment.response_type_to_response_keys.get("summary", {})
):
response_key = displayed_key_to_response_key["summary"](displayed_response_key)[
0
Expand Down
42 changes: 41 additions & 1 deletion tests/ert/unit_tests/gui/tools/plot/test_plot_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from pandas.testing import assert_frame_equal
from starlette.testclient import TestClient

from ert.config import GenKwConfig, SummaryConfig
from ert.config import GenDataConfig, GenKwConfig, SummaryConfig
from ert.dark_storage import enkf
from ert.dark_storage.app import app
from ert.gui.tools.plot.plot_api import PlotApi, PlotApiKeyDefinition
Expand Down Expand Up @@ -326,3 +326,43 @@ def test_that_multiple_observations_are_parsed_correctly(api):
ensemble = next(x for x in api.get_all_ensembles() if x.id == "ens_id_5")
obs_data = api.observations_for_key([ensemble.id], "WOPR:OP1")
assert obs_data.shape == (3, 6)


def test_that_observations_for_empty_ensemble_returns_empty_data(api_and_storage):
api, storage = api_and_storage
key = "NAIMFRAC"
expected_genobs = polars.DataFrame(
{
"observation_key": "gen_data",
"response_key": ["gen_data_0"],
"report_step": polars.Series([0], dtype=polars.UInt16),
"index": polars.Series([0], dtype=polars.UInt16),
"observations": polars.Series([13.37], dtype=polars.Float32),
"std": polars.Series([0.15], dtype=polars.Float32),
}
)

experiment = storage.create_experiment(
parameters=[],
responses=[
GenDataConfig(
name="gen_data",
report_steps_list=[[0]],
keys=["gen_data_0"],
),
SummaryConfig(
name="summary",
input_files=[""],
keys=[key],
),
],
observations={"gen_data": expected_genobs},
)
ensemble = storage.create_ensemble(experiment.id, ensemble_size=695)

# Important to request a non-existing gen data key here
# so it hits the summary-request logic clause and finds that there
# is no
gen_obs = api.observations_for_key([str(ensemble.id)], "gen_data_0@1")

assert gen_obs.empty

0 comments on commit 10e712a

Please sign in to comment.