From da3440e4744726f3f645ba3a3f240e9d8ac17d16 Mon Sep 17 00:00:00 2001 From: Manuel Schlund <32543114+schlunma@users.noreply.github.com> Date: Fri, 11 Oct 2024 14:45:54 +0200 Subject: [PATCH] Remove deprecated statistical operators (#2553) Co-authored-by: Valeriu Predoi --- esmvalcore/preprocessor/_shared.py | 27 ------------------- .../_multimodel/test_multimodel.py | 7 ----- tests/unit/preprocessor/test_shared.py | 24 +++-------------- 3 files changed, 3 insertions(+), 55 deletions(-) diff --git a/esmvalcore/preprocessor/_shared.py b/esmvalcore/preprocessor/_shared.py index 04490bdda4..49272771b5 100644 --- a/esmvalcore/preprocessor/_shared.py +++ b/esmvalcore/preprocessor/_shared.py @@ -7,7 +7,6 @@ from __future__ import annotations import logging -import re import warnings from collections import defaultdict from collections.abc import Callable, Iterable @@ -22,7 +21,6 @@ from iris.exceptions import CoordinateMultiDimError, CoordinateNotFoundError from iris.util import broadcast_to_shape -from esmvalcore.exceptions import ESMValCoreDeprecationWarning from esmvalcore.iris_helpers import has_regular_grid from esmvalcore.typing import DataType @@ -74,31 +72,6 @@ def get_iris_aggregator( cap_operator = operator.upper() aggregator_kwargs = dict(operator_kwargs) - # Deprecations - if cap_operator == "STD": - msg = ( - f"The operator '{operator}' for computing the standard deviation " - f"has been deprecated in ESMValCore version 2.10.0 and is " - f"scheduled for removal in version 2.12.0. Please use 'std_dev' " - f"instead. This is an exact replacement." - ) - warnings.warn(msg, ESMValCoreDeprecationWarning) - operator = "std_dev" - cap_operator = "STD_DEV" - elif re.match(r"^(P\d{1,2})(\.\d*)?$", cap_operator): - msg = ( - f"Specifying percentile operators with the syntax 'pXX.YY' (here: " - f"'{operator}') has been deprecated in ESMValCore version 2.10.0 " - f"and is scheduled for removal in version 2.12.0. Please use " - f"`operator='percentile'` with the keyword argument " - f"`percent=XX.YY` instead. Example: `percent=95.0` for 'p95.0'. " - f"This is an exact replacement." - ) - warnings.warn(msg, ESMValCoreDeprecationWarning) - aggregator_kwargs["percent"] = float(operator[1:]) - operator = "percentile" - cap_operator = "PERCENTILE" - # Check if valid aggregator is found if not hasattr(iris.analysis, cap_operator): raise ValueError( diff --git a/tests/unit/preprocessor/_multimodel/test_multimodel.py b/tests/unit/preprocessor/_multimodel/test_multimodel.py index 5bc5513451..39c11c944c 100644 --- a/tests/unit/preprocessor/_multimodel/test_multimodel.py +++ b/tests/unit/preprocessor/_multimodel/test_multimodel.py @@ -247,23 +247,17 @@ def get_cube_for_equal_coords_test(num_cubes): ("full", "mean", (5, 5, 3)), ("full", {"operator": "mean"}, (5, 5, 3)), ("full", "std_dev", (5.656854249492381, 4, 2.8284271247461903)), - ("full", "std", (5.656854249492381, 4, 2.8284271247461903)), ("full", "min", (1, 1, 1)), ("full", "max", (9, 9, 5)), ("full", "median", (5, 5, 3)), ("full", {"operator": "percentile", "percent": 50.0}, (5, 5, 3)), - ("full", "p50", (5, 5, 3)), - ("full", "p99.5", (8.96, 8.96, 4.98)), ("full", "peak", (9, 9, 5)), ("overlap", "mean", (5, 5)), ("overlap", "std_dev", (5.656854249492381, 4)), - ("overlap", "std", (5.656854249492381, 4)), ("overlap", "min", (1, 1)), ("overlap", "max", (9, 9)), ("overlap", "median", (5, 5)), ("overlap", {"operator": "percentile", "percent": 50.0}, (5, 5)), - ("overlap", "p50", (5, 5)), - ("overlap", "p99.5", (8.96, 8.96)), ("overlap", "peak", (9, 9)), # test multiple statistics ("overlap", ("min", "max"), ((1, 1), (9, 9))), @@ -1470,7 +1464,6 @@ def test_empty_input_ensemble_statistics(): {"operator": "median"}, "min", "max", - "p42.314", {"operator": "percentile", "percent": 42.314}, "std_dev", ] diff --git a/tests/unit/preprocessor/test_shared.py b/tests/unit/preprocessor/test_shared.py index 02a48991ba..b0a990c45d 100644 --- a/tests/unit/preprocessor/test_shared.py +++ b/tests/unit/preprocessor/test_shared.py @@ -11,7 +11,6 @@ from iris.coords import AuxCoord from iris.cube import Cube -from esmvalcore.exceptions import ESMValCoreDeprecationWarning from esmvalcore.preprocessor import PreprocessorFile from esmvalcore.preprocessor._shared import ( _compute_area_weights, @@ -91,16 +90,6 @@ def test_get_iris_aggregator_percentile(operator, kwargs): assert agg_kwargs == kwargs -@pytest.mark.parametrize("kwargs", [{}, {"alphap": 0.5}]) -@pytest.mark.parametrize("operator", ["p10", "P10.5"]) -def test_get_iris_aggregator_pxxyy(operator, kwargs): - """Test ``get_iris_aggregator``.""" - with pytest.warns(ESMValCoreDeprecationWarning): - (agg, agg_kwargs) = get_iris_aggregator(operator, **kwargs) - assert agg == iris.analysis.PERCENTILE - assert agg_kwargs == {"percent": float(operator[1:]), **kwargs} - - @pytest.mark.parametrize("kwargs", [{}, {"weights": True}]) @pytest.mark.parametrize("operator", ["rms", "rMs", "RMS"]) def test_get_iris_aggregator_rms(operator, kwargs): @@ -111,18 +100,11 @@ def test_get_iris_aggregator_rms(operator, kwargs): @pytest.mark.parametrize("kwargs", [{}, {"ddof": 1}]) -@pytest.mark.parametrize("operator", ["std", "STD", "std_dev", "STD_DEV"]) +@pytest.mark.parametrize("operator", ["std_dev", "STD_DEV"]) def test_get_iris_aggregator_std(operator, kwargs): """Test ``get_iris_aggregator``.""" - if operator.lower() == "std": - with pytest.warns(ESMValCoreDeprecationWarning): - (agg, agg_kwargs) = get_iris_aggregator(operator, **kwargs) - else: - with warnings.catch_warnings(): - warnings.simplefilter( - "error", category=ESMValCoreDeprecationWarning - ) - (agg, agg_kwargs) = get_iris_aggregator(operator, **kwargs) + with warnings.catch_warnings(): + (agg, agg_kwargs) = get_iris_aggregator(operator, **kwargs) assert agg == iris.analysis.STD_DEV assert agg_kwargs == kwargs