Skip to content

Commit

Permalink
Remove deprecated statistical operators (#2553)
Browse files Browse the repository at this point in the history
Co-authored-by: Valeriu Predoi <[email protected]>
  • Loading branch information
schlunma and valeriupredoi authored Oct 11, 2024
1 parent 892d4a3 commit da3440e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 55 deletions.
27 changes: 0 additions & 27 deletions esmvalcore/preprocessor/_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from __future__ import annotations

import logging
import re
import warnings
from collections import defaultdict
from collections.abc import Callable, Iterable
Expand All @@ -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

Expand Down Expand Up @@ -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(
Expand Down
7 changes: 0 additions & 7 deletions tests/unit/preprocessor/_multimodel/test_multimodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))),
Expand Down Expand Up @@ -1470,7 +1464,6 @@ def test_empty_input_ensemble_statistics():
{"operator": "median"},
"min",
"max",
"p42.314",
{"operator": "percentile", "percent": 42.314},
"std_dev",
]
Expand Down
24 changes: 3 additions & 21 deletions tests/unit/preprocessor/test_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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):
Expand All @@ -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

Expand Down

0 comments on commit da3440e

Please sign in to comment.