From 9440e0b8bff970b4983c77f327252196d5262a45 Mon Sep 17 00:00:00 2001 From: saschahofmann Date: Thu, 19 Sep 2024 22:34:35 +0200 Subject: [PATCH 1/4] Replace deprecated alias A with Y --- tests/test_indicators.py | 3 +-- xclim/core/indicator.py | 7 +++---- xclim/core/utils.py | 3 +-- xclim/indicators/atmos/_temperature.py | 7 ++++--- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/tests/test_indicators.py b/tests/test_indicators.py index 29aa1a988..37f1b42e5 100644 --- a/tests/test_indicators.py +++ b/tests/test_indicators.py @@ -1,7 +1,6 @@ # pylint: disable=unsubscriptable-object,function-redefined # Tests for the Indicator objects from __future__ import annotations - import gc import json from inspect import signature @@ -885,6 +884,6 @@ def test_freq_doc(): from xclim import atmos doc = atmos.latitude_temperature_index.__doc__ - allowed_periods = ["A"] + allowed_periods = ["Y"] exp = f"Restricted to frequencies equivalent to one of {allowed_periods}" assert exp in doc diff --git a/xclim/core/indicator.py b/xclim/core/indicator.py index 48e296e31..c5bb22556 100644 --- a/xclim/core/indicator.py +++ b/xclim/core/indicator.py @@ -100,7 +100,6 @@ """ from __future__ import annotations - import re import warnings import weakref @@ -109,9 +108,8 @@ from dataclasses import asdict, dataclass from functools import reduce from inspect import Parameter as _Parameter -from inspect import Signature +from inspect import Signature, signature from inspect import _empty as _empty_default # noqa -from inspect import signature from os import PathLike from pathlib import Path from types import ModuleType @@ -167,6 +165,7 @@ load_module, ) + # Indicators registry registry = {} # Main class registry base_registry = {} @@ -1495,7 +1494,7 @@ class ResamplingIndicator(CheckMissingIndicator): If None, this will be determined by the global configuration. allowed_periods : Sequence[str], optional A list of allowed periods, i.e. base parts of the `freq` parameter. - For example, indicators meant to be computed annually only will have `allowed_periods=["A"]`. + For example, indicators meant to be computed annually only will have `allowed_periods=["Y"]`. `None` means "any period" or that the indicator doesn't take a `freq` argument. """ diff --git a/xclim/core/utils.py b/xclim/core/utils.py index cee032de8..44c5929db 100644 --- a/xclim/core/utils.py +++ b/xclim/core/utils.py @@ -6,7 +6,6 @@ """ from __future__ import annotations - import functools import importlib.util import logging @@ -24,6 +23,7 @@ from dask import array as dsk from yaml import safe_dump, safe_load + logger = logging.getLogger("xclim") @@ -578,7 +578,6 @@ def adapt_clix_meta_yaml( # noqa: C901 """Read in a clix-meta yaml representation and refactor it to fit xclim's yaml specifications.""" from ..indices import generic # pylint: disable=import-outside-toplevel - # freq_names = {"annual": "A", "seasonal": "Q", "monthly": "M", "weekly": "W"} freq_defs = {"annual": "YS", "seasonal": "QS-DEC", "monthly": "MS", "weekly": "W"} if isinstance(raw, os.PathLike): diff --git a/xclim/indicators/atmos/_temperature.py b/xclim/indicators/atmos/_temperature.py index 661169468..142a4c994 100644 --- a/xclim/indicators/atmos/_temperature.py +++ b/xclim/indicators/atmos/_temperature.py @@ -7,6 +7,7 @@ from xclim.core.indicator import Daily, Indicator, ResamplingIndicatorWithIndexing from xclim.core.utils import InputKind + __all__ = [ "australian_hardiness_zones", "biologically_effective_degree_days", @@ -1383,7 +1384,7 @@ def cfcheck(self, tas, snd=None): "Mean temperature of warmest month multiplied by the difference of latitude factor coefficient minus latitude. " "Metric originally published in Jackson, D. I., & Cherry, N. J. (1988).", cell_methods="", - allowed_periods=["A"], + allowed_periods=["Y"], var_name="lti", compute=indices.latitude_temperature_index, parameters={"lat": {"kind": InputKind.VARIABLE}, "lat_factor": 60}, @@ -1419,7 +1420,7 @@ def cfcheck(self, tas, snd=None): "Botanical Gardens (ANBG) classification scheme divides categories into 5-degree Celsius zones, starting from -15 " "degrees Celsius and ending at 20 degrees Celsius.", cell_methods="", - allowed_periods=["A"], + allowed_periods=["Y"], var_name="hz", compute=indices.hardiness_zones, parameters={"method": "anbg"}, @@ -1440,7 +1441,7 @@ def cfcheck(self, tas, snd=None): "scheme divides categories into 10 degree Fahrenheit zones, with 5-degree Fahrenheit half-zones, " "starting from -65 degrees Fahrenheit and ending at 65 degrees Fahrenheit.", cell_methods="", - allowed_periods=["A"], + allowed_periods=["Y"], var_name="hz", compute=indices.hardiness_zones, parameters={"method": "usda"}, From adea760250c127b9f07e2ffa01b5d4f2a272d02c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 19 Sep 2024 20:36:28 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/test_indicators.py | 1 + xclim/core/indicator.py | 2 +- xclim/core/utils.py | 2 +- xclim/indicators/atmos/_temperature.py | 1 - 4 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_indicators.py b/tests/test_indicators.py index 37f1b42e5..5a1cdba78 100644 --- a/tests/test_indicators.py +++ b/tests/test_indicators.py @@ -1,6 +1,7 @@ # pylint: disable=unsubscriptable-object,function-redefined # Tests for the Indicator objects from __future__ import annotations + import gc import json from inspect import signature diff --git a/xclim/core/indicator.py b/xclim/core/indicator.py index c5bb22556..2c8f38c49 100644 --- a/xclim/core/indicator.py +++ b/xclim/core/indicator.py @@ -100,6 +100,7 @@ """ from __future__ import annotations + import re import warnings import weakref @@ -165,7 +166,6 @@ load_module, ) - # Indicators registry registry = {} # Main class registry base_registry = {} diff --git a/xclim/core/utils.py b/xclim/core/utils.py index 44c5929db..b28d7f550 100644 --- a/xclim/core/utils.py +++ b/xclim/core/utils.py @@ -6,6 +6,7 @@ """ from __future__ import annotations + import functools import importlib.util import logging @@ -23,7 +24,6 @@ from dask import array as dsk from yaml import safe_dump, safe_load - logger = logging.getLogger("xclim") diff --git a/xclim/indicators/atmos/_temperature.py b/xclim/indicators/atmos/_temperature.py index 142a4c994..d1efd311a 100644 --- a/xclim/indicators/atmos/_temperature.py +++ b/xclim/indicators/atmos/_temperature.py @@ -7,7 +7,6 @@ from xclim.core.indicator import Daily, Indicator, ResamplingIndicatorWithIndexing from xclim.core.utils import InputKind - __all__ = [ "australian_hardiness_zones", "biologically_effective_degree_days", From 41e271ece5241029728dd37811a5cfd6a0d41cb6 Mon Sep 17 00:00:00 2001 From: saschahofmann Date: Fri, 20 Sep 2024 17:47:20 +0200 Subject: [PATCH 3/4] Add to changelog --- CHANGELOG.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index b28b0e176..a892a6ecf 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -42,6 +42,7 @@ Internal changes * The codebase has been adjusted to address many `pylint`-related warnings and errors. In some cases, `casting` was used to redefine some `numpy` and `xarray` objects. (:issue:`1719`, :pull:`1881`). * ``xclim.core`` now uses absolute imports for clarity and some objects commonly used in the module have been moved to hidden submodules. (:issue:`1719`, :pull:`1881`). * ``xclim.core.indicator.Parameter`` has a new attribute ``compute_name`` while ``xclim.core.indicator.Indicator`` lost its ``_variable_mapping``. The translation from parameter (and variable) names in the indicator to the names on the compute function is handled by ``Indicator._get_compute_args``. (:pull:`1885`). +* Renamed annual deprecated frequency alias `"A"` to `"Y"` (:pull:`1930`). v0.52.0 (2024-08-08) -------------------- From 770d5c9c0c62f0df3b957ca3d28fea84b7557af3 Mon Sep 17 00:00:00 2001 From: saschahofmann Date: Fri, 20 Sep 2024 17:49:08 +0200 Subject: [PATCH 4/4] Bring back change --- CHANGELOG.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 1fb325df6..868e9acc7 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -52,6 +52,7 @@ Internal changes * Added formatting for `Markdown` files. * Added the `bugbear`, `pyupgrade` checks to the `ruff` formatter. * Adjusted `mypy` checks to be more standardized. +* Renamed annual deprecated frequency alias `"A"` to `"Y"` (:pull:`1930`). CI changes ^^^^^^^^^^