From f57e39670f946b927f28c438fcaf46455541c169 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Eide?= Date: Wed, 19 Jun 2024 10:22:11 +0200 Subject: [PATCH] Review comment --- .../workflows/export_misfit_data.py | 14 ++++++-------- .../workflows/export_runpath.py | 10 +++------- tests/unit_tests/all/plugins/test_export_misfit.py | 4 ++-- .../unit_tests/all/plugins/test_export_runpath.py | 2 +- .../gui/plottery/test_plotting_of_snake_oil.py | 5 ++++- 5 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/ert/shared/hook_implementations/workflows/export_misfit_data.py b/src/ert/shared/hook_implementations/workflows/export_misfit_data.py index f4f3fd453b9..1eb31a8024b 100644 --- a/src/ert/shared/hook_implementations/workflows/export_misfit_data.py +++ b/src/ert/shared/hook_implementations/workflows/export_misfit_data.py @@ -1,6 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Optional +from typing import TYPE_CHECKING, Any, List + +import pandas as pd from ert import ErtScript from ert.exceptions import StorageError @@ -22,13 +24,9 @@ class ExportMisfitDataJob(ErtScript): """ def run( - self, - ert_config: ErtConfig, - ensemble: Ensemble, - target_file: Optional[str] = None, + self, ert_config: ErtConfig, ensemble: Ensemble, workflow_args: List[Any] ) -> None: - if target_file is None: - target_file = "misfit.hdf" + target_file = "misfit.hdf" if not workflow_args else workflow_args[0] realizations = ensemble.get_realization_with_responses() @@ -38,6 +36,6 @@ def run( misfit = facade.load_all_misfit_data(ensemble) if realizations.size == 0 or misfit.empty: raise StorageError("No responses loaded") - misfit.columns = [val.split(":")[1] for val in misfit.columns] + misfit.columns = pd.Index([val.split(":")[1] for val in misfit.columns]) misfit = misfit.drop("TOTAL", axis=1) misfit.to_hdf(target_file, key="misfit", mode="w") diff --git a/src/ert/shared/hook_implementations/workflows/export_runpath.py b/src/ert/shared/hook_implementations/workflows/export_runpath.py index b874f0a965f..58c4b3125a0 100644 --- a/src/ert/shared/hook_implementations/workflows/export_runpath.py +++ b/src/ert/shared/hook_implementations/workflows/export_runpath.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, List, Optional, Tuple +from typing import TYPE_CHECKING, Any, List, Tuple from ert.config import ErtScript from ert.runpaths import Runpaths @@ -33,12 +33,8 @@ class ExportRunpathJob(ErtScript): file. """ - def run( - self, ert_config: ErtConfig, workflow_args: Optional[List[str]] = None - ) -> None: - input_ranges = workflow_args[0] if len(workflow_args) != 0 else None - input_ranges = [] if input_ranges is None else input_ranges - _args = " ".join(input_ranges).split() # Make sure args is a list of words + def run(self, ert_config: ErtConfig, workflow_args: List[Any]) -> None: + _args = " ".join(workflow_args).split() # Make sure args is a list of words run_paths = Runpaths( jobname_format=ert_config.model_config.jobname_format_string, runpath_format=ert_config.model_config.runpath_format_string, diff --git a/tests/unit_tests/all/plugins/test_export_misfit.py b/tests/unit_tests/all/plugins/test_export_misfit.py index 61fdc946361..56f0a6c7758 100644 --- a/tests/unit_tests/all/plugins/test_export_misfit.py +++ b/tests/unit_tests/all/plugins/test_export_misfit.py @@ -15,7 +15,7 @@ reason="https://github.com/equinor/ert/issues/7533", ) def test_export_misfit(snake_oil_case_storage, snake_oil_default_storage, snapshot): - ExportMisfitDataJob().run(snake_oil_case_storage, snake_oil_default_storage) + ExportMisfitDataJob().run(snake_oil_case_storage, snake_oil_default_storage, []) result = pd.read_hdf("misfit.hdf").round(10) snapshot.assert_match( result.to_csv(), @@ -25,7 +25,7 @@ def test_export_misfit(snake_oil_case_storage, snake_oil_default_storage, snapsh def test_export_misfit_no_responses_in_storage(poly_case, new_ensemble): with pytest.raises(StorageError, match="No responses loaded"): - ExportMisfitDataJob().run(poly_case, new_ensemble) + ExportMisfitDataJob().run(poly_case, new_ensemble, []) def test_export_misfit_data_job_is_loaded(): diff --git a/tests/unit_tests/all/plugins/test_export_runpath.py b/tests/unit_tests/all/plugins/test_export_runpath.py index 30cf7de00cc..8fc0cb112c9 100644 --- a/tests/unit_tests/all/plugins/test_export_runpath.py +++ b/tests/unit_tests/all/plugins/test_export_runpath.py @@ -30,7 +30,7 @@ def writing_setup(setup_case): def test_export_runpath_empty_range(writing_setup): writing_setup, config = writing_setup - writing_setup.export_job.run(config) + writing_setup.export_job.run(config, []) writing_setup.write_mock.assert_called_with( [0], diff --git a/tests/unit_tests/gui/plottery/test_plotting_of_snake_oil.py b/tests/unit_tests/gui/plottery/test_plotting_of_snake_oil.py index f2ac81422a4..66f29ab6f0f 100644 --- a/tests/unit_tests/gui/plottery/test_plotting_of_snake_oil.py +++ b/tests/unit_tests/gui/plottery/test_plotting_of_snake_oil.py @@ -18,6 +18,7 @@ from ert.services import StorageService from ert.storage import open_storage + # Use a fixture for the fligure in order for the lifetime # of the c++ gui element to not go out before mpl_image_compare @pytest.fixture( @@ -40,7 +41,9 @@ def plot_figure(qtbot, snake_oil_case_storage, request): with StorageService.init_service( project=snake_oil_case_storage.ert_config.ens_path, ), open_storage(snake_oil_case_storage.ert_config.ens_path) as storage: - gui = _setup_main_window(snake_oil_case_storage, args_mock, log_handler, storage) + gui = _setup_main_window( + snake_oil_case_storage, args_mock, log_handler, storage + ) qtbot.addWidget(gui) plot_tool = gui.tools["Create plot"]