From 9eae710224c67a40cc971098a62e9624025f1e44 Mon Sep 17 00:00:00 2001 From: Anna Kvashchuk Date: Wed, 13 Dec 2023 14:01:54 +0100 Subject: [PATCH] Fix failing tests --- src/ert/config/field.py | 2 +- src/ert/config/surface_config.py | 2 +- tests/unit_tests/analysis/test_es_update.py | 12 ++++++++---- .../migration/test_block_fs_simple_case.py | 8 ++++---- .../storage/test_parameter_sample_types.py | 17 ++++++++--------- 5 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/ert/config/field.py b/src/ert/config/field.py index bd775acc698..815fa563dc2 100644 --- a/src/ert/config/field.py +++ b/src/ert/config/field.py @@ -180,7 +180,7 @@ def write_to_runpath( def _fetch_from_ensemble( self, real_nr: int, ensemble: EnsembleReader ) -> xr.DataArray: - da = ensemble.load_parameters(self.name, real_nr) + da = ensemble.load_parameters(self.name, real_nr)["values"] assert isinstance(da, xr.DataArray) return da diff --git a/src/ert/config/surface_config.py b/src/ert/config/surface_config.py index fdd6d4db4c8..bd1a929e382 100644 --- a/src/ert/config/surface_config.py +++ b/src/ert/config/surface_config.py @@ -119,7 +119,7 @@ def read_from_runpath(self, run_path: Path, real_nr: int) -> xr.Dataset: def write_to_runpath( self, run_path: Path, real_nr: int, ensemble: EnsembleReader ) -> None: - data = ensemble.load_parameters(self.name, real_nr) + data = ensemble.load_parameters(self.name, real_nr)["values"] surf = xtgeo.RegularSurface( ncol=self.ncol, diff --git a/tests/unit_tests/analysis/test_es_update.py b/tests/unit_tests/analysis/test_es_update.py index ecdcb814218..5b051443fe2 100644 --- a/tests/unit_tests/analysis/test_es_update.py +++ b/tests/unit_tests/analysis/test_es_update.py @@ -231,10 +231,12 @@ def test_update_snapshot( np.random.default_rng(3593114179000630026631423308983283277868), ) - sim_gen_kw = list(prior_ens.load_parameters("SNAKE_OIL_PARAM", 0).values.flatten()) + sim_gen_kw = list( + prior_ens.load_parameters("SNAKE_OIL_PARAM", 0)["values"].values.flatten() + ) target_gen_kw = list( - posterior_ens.load_parameters("SNAKE_OIL_PARAM", 0).values.flatten() + posterior_ens.load_parameters("SNAKE_OIL_PARAM", 0)["values"].values.flatten() ) assert sim_gen_kw != target_gen_kw @@ -386,10 +388,12 @@ def test_localization( rng=np.random.default_rng(3593114179000630026631423308983283277868), ) - sim_gen_kw = list(prior_ens.load_parameters("SNAKE_OIL_PARAM", 0).values.flatten()) + sim_gen_kw = list( + prior_ens.load_parameters("SNAKE_OIL_PARAM", 0)["values"].values.flatten() + ) target_gen_kw = list( - posterior_ens.load_parameters("SNAKE_OIL_PARAM", 0).values.flatten() + posterior_ens.load_parameters("SNAKE_OIL_PARAM", 0)["values"].values.flatten() ) # Test that the localized values has been updated diff --git a/tests/unit_tests/storage/migration/test_block_fs_simple_case.py b/tests/unit_tests/storage/migration/test_block_fs_simple_case.py index eeac40e5687..9251c0e3210 100644 --- a/tests/unit_tests/storage/migration/test_block_fs_simple_case.py +++ b/tests/unit_tests/storage/migration/test_block_fs_simple_case.py @@ -71,7 +71,7 @@ def test_migrate_surface(data, storage, parameter, ens_config): for key, var in data["/REAL_0/SURFACE"].groups.items(): expect = sorted_surface(var) - actual = ensemble.load_parameters(key, 0).values.ravel() + actual = ensemble.load_parameters(key, 0)["values"].values.ravel() assert list(expect) == list(actual), key @@ -84,7 +84,7 @@ def test_migrate_field(data, storage, parameter, ens_config): for key, var in data["/REAL_0/FIELD"].groups.items(): expect = np.array(var["VALUES"]).ravel() - actual = ensemble.load_parameters(key, [0]).values.ravel() + actual = ensemble.load_parameters(key, [0])["values"].values.ravel() assert list(expect) == list(actual), key @@ -101,13 +101,13 @@ def test_migrate_case(data, storage, enspath): # Compare FIELDs for key, data in real_group["FIELD"].groups.items(): expect = np.array(data["VALUES"]).ravel() - actual = ensemble.load_parameters(key, [real_index]) + actual = ensemble.load_parameters(key, [real_index])["values"] assert list(expect) == list(actual.values.ravel()), f"FIELD {key}" # Compare SURFACEs for key, data in real_group["SURFACE"].groups.items(): expect = sorted_surface(data) - actual = ensemble.load_parameters(key, real_index).values.ravel() + actual = ensemble.load_parameters(key, real_index)["values"].values.ravel() assert list(expect) == list(actual), f"SURFACE {key}" diff --git a/tests/unit_tests/storage/test_parameter_sample_types.py b/tests/unit_tests/storage/test_parameter_sample_types.py index cbe44888561..bebc31a98d5 100644 --- a/tests/unit_tests/storage/test_parameter_sample_types.py +++ b/tests/unit_tests/storage/test_parameter_sample_types.py @@ -313,7 +313,6 @@ def test_that_order_of_input_in_user_input_is_abritrary_for_gen_kw_init_files( def test_surface_param( storage, tmpdir, - config_str, expect_forward_init, expect_num_loaded, error, @@ -550,9 +549,9 @@ def test_that_sampling_is_fixed_from_name( key_hash = sha256(b"1234" + b"KW_NAME:MY_KEYWORD") seed = np.frombuffer(key_hash.digest(), dtype="uint32") expected = np.random.default_rng(seed).standard_normal(num_realisations) - assert fs.load_parameters("KW_NAME").sel( - names="MY_KEYWORD" - ).values.ravel().tolist() == list(expected) + assert fs.load_parameters("KW_NAME").sel(names="MY_KEYWORD")[ + "values" + ].values.ravel().tolist() == list(expected) @pytest.mark.parametrize( @@ -614,7 +613,7 @@ def test_that_sub_sample_maintains_order(tmpdir, storage, mask, expected): assert ( fs.load_parameters("KW_NAME") - .sel(names="MY_KEYWORD") + .sel(names="MY_KEYWORD")["values"] .values.ravel() .tolist() == expected @@ -740,7 +739,7 @@ def test_surface_param_update(tmpdir): .T ) posterior_param = ( - posterior.load_parameters("MY_PARAM", range(5)) + posterior.load_parameters("MY_PARAM", range(5))["values"] .values.reshape(5, 2 * 3) .T ) @@ -914,6 +913,6 @@ def test_gen_kw_optional_template(storage, tmpdir, config_str, expected): fh.writelines("MY_KEYWORD NORMAL 0 1") create_runpath(storage, "config.ert") - assert list(storage.ensembles)[0].load_parameters( - "KW_NAME" - ).values.flatten().tolist() == pytest.approx([expected]) + assert list(storage.ensembles)[0].load_parameters("KW_NAME")[ + "values" + ].values.flatten().tolist() == pytest.approx([expected])