diff --git a/src/ert/gui/tools/manage_experiments/storage_info_widget.py b/src/ert/gui/tools/manage_experiments/storage_info_widget.py index 64fb5b4b211..2d845312f4f 100644 --- a/src/ert/gui/tools/manage_experiments/storage_info_widget.py +++ b/src/ert/gui/tools/manage_experiments/storage_info_widget.py @@ -223,9 +223,17 @@ def _filter_on_observation_label(df: polars.DataFrame) -> polars.DataFrame: obs = _filter_on_observation_label(obs) response_key = obs["response_key"].unique().to_list()[0] - response_ds = self._ensemble.load_responses( - response_key, - tuple(self._ensemble.get_realization_list_with_responses()), + reals_with_responses = tuple( + self._ensemble.get_realization_list_with_responses() + ) + + response_ds = ( + self._ensemble.load_responses( + response_key, + reals_with_responses, + ) + if reals_with_responses + else None ) scaling_df = self._ensemble.load_observation_scaling_factors() @@ -260,7 +268,7 @@ def _try_render_scaled_obs() -> None: color="black", ) - if not response_ds.is_empty(): + if response_ds is not None and not response_ds.is_empty(): response_ds_for_label = _filter_on_observation_label(response_ds).rename( {"values": "Responses"} )[["response_key", "Responses"]] diff --git a/tests/ert/ui_tests/gui/test_manage_experiments_tool.py b/tests/ert/ui_tests/gui/test_manage_experiments_tool.py index 1484262575a..9e6994c3aa3 100644 --- a/tests/ert/ui_tests/gui/test_manage_experiments_tool.py +++ b/tests/ert/ui_tests/gui/test_manage_experiments_tool.py @@ -1,10 +1,12 @@ +import datetime import shutil +import polars import pytest from qtpy.QtCore import Qt from qtpy.QtWidgets import QPushButton, QTextEdit -from ert.config import ErtConfig +from ert.config import ErtConfig, SummaryConfig from ert.gui.ertnotifier import ErtNotifier from ert.gui.tools.manage_experiments import ManageExperimentsPanel from ert.gui.tools.manage_experiments.storage_info_widget import ( @@ -343,6 +345,67 @@ def _evaluate(coeffs, x): ) +@pytest.mark.usefixtures("copy_poly_case") +def test_ensemble_observations_view_on_empty_ensemble(qtbot): + config = ErtConfig.from_file("poly.ert") + notifier = ErtNotifier(config.config_path) + with open_storage(config.ens_path, mode="w") as storage: + notifier.set_storage(storage) + storage.create_experiment( + responses=[SummaryConfig(keys=["*"])], + observations={ + "summary": polars.DataFrame( + polars.DataFrame( + { + "response_key": ["FOPR"], + "observation_key": ["O4"], + "time": polars.Series( + [datetime.datetime(2000, 1, 1)], + dtype=polars.Datetime("ms"), + ), + "observations": polars.Series([10.2], dtype=polars.Float32), + "std": polars.Series([0.1], dtype=polars.Float32), + } + ) + ), + }, + ).create_ensemble( + name="test", ensemble_size=config.model_config.num_realizations + ) + + tool = ManageExperimentsPanel( + config, notifier, config.model_config.num_realizations + ) + + # select the ensemble + storage_widget = tool.findChild(StorageWidget) + storage_widget._tree_view.expandAll() + model_index = storage_widget._tree_view.model().index( + 0, 0, storage_widget._tree_view.model().index(0, 0) + ) + storage_widget._tree_view.setCurrentIndex(model_index) + assert ( + tool._storage_info_widget._content_layout.currentIndex() + == _WidgetType.ENSEMBLE_WIDGET + ) + + ensemble_widget = tool._storage_info_widget._content_layout.currentWidget() + assert isinstance(ensemble_widget, _EnsembleWidget) + assert ensemble_widget._name_label.text() + assert ensemble_widget._uuid_label.text() + assert not ensemble_widget._state_text_edit.toPlainText() + + ensemble_widget._tab_widget.setCurrentIndex(_EnsembleWidgetTabs.STATE_TAB) + assert ensemble_widget._state_text_edit.toPlainText() + + ensemble_widget._tab_widget.setCurrentIndex( + _EnsembleWidgetTabs.OBSERVATIONS_TAB + ) + + # Expect only one figure, the one for the observation + assert len(ensemble_widget._figure.get_axes()) == 1 + + def test_realization_view( qtbot, snake_oil_case_storage: ErtConfig, snake_oil_storage: Storage ):