From 858cc2275478a289f6385136fbc540cf5a8b0212 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 7 Oct 2024 16:29:03 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks --- .../tutorials/notebooks/DCSC_txnn.ipynb | 14 +++++++------ .../notebooks/averaged_tas_anomaly.ipynb | 4 ++-- .../notebooks/cold_spell_duration.ipynb | 6 +++--- .../notebooks/custom_freezing_tas.ipynb | 3 ++- .../notebooks/deltaT_deltaP_anomaly.ipynb | 3 ++- .../su_summer_days__subset_and_plot.ipynb | 3 ++- .../tg90p_calculate__subset_and_plot.ipynb | 3 ++- .../_core/generic/threshold/percentile.py | 2 +- tests/test_cf_calendar.py | 1 + tests/test_dcsc.py | 1 - tests/test_ecad_indices.py | 1 + tests/test_frequency.py | 2 +- tests/test_generated_api.py | 20 +++++++++---------- tests/test_generic_functions.py | 1 - tests/test_index_group.py | 1 + tests/test_input_parsing.py | 1 + tests/test_main.py | 8 ++++---- tests/test_rechunk.py | 1 + tests/test_threshold.py | 5 +++-- tests/test_user_index.py | 4 ++-- tests/testing_utils.py | 1 + tools/extract_icclim_funs.py | 10 ++++++---- 22 files changed, 54 insertions(+), 41 deletions(-) diff --git a/doc/source/tutorials/notebooks/DCSC_txnn.ipynb b/doc/source/tutorials/notebooks/DCSC_txnn.ipynb index 8cc628ad..963e128b 100644 --- a/doc/source/tutorials/notebooks/DCSC_txnn.ipynb +++ b/doc/source/tutorials/notebooks/DCSC_txnn.ipynb @@ -47,19 +47,19 @@ } ], "source": [ - "import datetime\n", "import sys\n", "from pathlib import Path\n", "\n", "import cartopy.crs as ccrs\n", "import cftime\n", - "import icclim\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "import pandas as pd\n", "import xarray as xr\n", "import xclim\n", - "from xclim.core.calendar import select_time \n", + "from xclim.core.calendar import select_time\n", + "\n", + "import icclim\n", "from icclim.frequency import FrequencyRegistry\n", "\n", "print(\"python: \", sys.version)\n", @@ -68,7 +68,7 @@ "print(\"pandas: \", pd.__version__)\n", "print(\"icclim: \", icclim.__version__)\n", "print(\"cftime: \", cftime.__version__)\n", - "print(\"xclim: \", xclim.__version__)\n" + "print(\"xclim: \", xclim.__version__)" ] }, { @@ -664,7 +664,9 @@ ], "source": [ "historical_tas = xr.open_mfdataset(historical_files).tas\n", - "filtered_tas = select_time(historical_tas, month=FrequencyRegistry.AMJJAS.indexer[\"month\"], drop=True)\n", + "filtered_tas = select_time(\n", + " historical_tas, month=FrequencyRegistry.AMJJAS.indexer[\"month\"], drop=True\n", + ")\n", "normal = filtered_tas.mean(dim=\"time\", keep_attrs=True)\n", "normal" ] @@ -1291,7 +1293,7 @@ "source": [ "icclim.dcsc.txnd(\n", " in_files=studied_files[0:1],\n", - " normal = normal,\n", + " normal=normal,\n", " var_name=\"tas\",\n", " slice_mode=FrequencyRegistry.AMJJAS,\n", " out_file=out_f,\n", diff --git a/doc/source/tutorials/notebooks/averaged_tas_anomaly.ipynb b/doc/source/tutorials/notebooks/averaged_tas_anomaly.ipynb index 80ac16e7..0d86bbed 100644 --- a/doc/source/tutorials/notebooks/averaged_tas_anomaly.ipynb +++ b/doc/source/tutorials/notebooks/averaged_tas_anomaly.ipynb @@ -125,13 +125,13 @@ "import sys\n", "from pathlib import Path\n", "\n", - "import icclim\n", - "\n", "# provides cftime axis in matplotlib\n", "import numpy as np\n", "import pandas as pd\n", "import xarray as xr\n", "\n", + "import icclim\n", + "\n", "print(\"python: \", sys.version)\n", "print(\"numpy: \", np.__version__)\n", "print(\"xarray: \", xr.__version__)\n", diff --git a/doc/source/tutorials/notebooks/cold_spell_duration.ipynb b/doc/source/tutorials/notebooks/cold_spell_duration.ipynb index d5c60d24..cca7885c 100644 --- a/doc/source/tutorials/notebooks/cold_spell_duration.ipynb +++ b/doc/source/tutorials/notebooks/cold_spell_duration.ipynb @@ -333,9 +333,6 @@ "# CDS API\n", "import cdsapi\n", "\n", - "# icclim package for calculating climate indices\n", - "import icclim\n", - "\n", "# Libraries for plotting and visualising data\n", "import matplotlib.pyplot as plt\n", "\n", @@ -346,6 +343,9 @@ "import urllib3\n", "import xarray as xr\n", "\n", + "# icclim package for calculating climate indices\n", + "import icclim\n", + "\n", "# To add specific units spelling\n", "\n", "urllib3.disable_warnings()\n", diff --git a/doc/source/tutorials/notebooks/custom_freezing_tas.ipynb b/doc/source/tutorials/notebooks/custom_freezing_tas.ipynb index a8e6ed29..280c147b 100644 --- a/doc/source/tutorials/notebooks/custom_freezing_tas.ipynb +++ b/doc/source/tutorials/notebooks/custom_freezing_tas.ipynb @@ -129,12 +129,13 @@ "\n", "import cartopy.crs as ccrs\n", "import cftime\n", - "import icclim\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "import pandas as pd\n", "import xarray as xr\n", "\n", + "import icclim\n", + "\n", "print(\"python: \", sys.version)\n", "print(\"numpy: \", np.__version__)\n", "print(\"xarray: \", xr.__version__)\n", diff --git a/doc/source/tutorials/notebooks/deltaT_deltaP_anomaly.ipynb b/doc/source/tutorials/notebooks/deltaT_deltaP_anomaly.ipynb index 88fc8b51..548e3102 100644 --- a/doc/source/tutorials/notebooks/deltaT_deltaP_anomaly.ipynb +++ b/doc/source/tutorials/notebooks/deltaT_deltaP_anomaly.ipynb @@ -131,12 +131,13 @@ "from pathlib import Path\n", "\n", "import cftime\n", - "import icclim\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "import pandas as pd\n", "import xarray as xr\n", "\n", + "import icclim\n", + "\n", "print(\"python: \", sys.version)\n", "print(\"numpy: \", np.__version__)\n", "print(\"xarray: \", xr.__version__)\n", diff --git a/doc/source/tutorials/notebooks/su_summer_days__subset_and_plot.ipynb b/doc/source/tutorials/notebooks/su_summer_days__subset_and_plot.ipynb index 2a6247f7..b01aa1f5 100644 --- a/doc/source/tutorials/notebooks/su_summer_days__subset_and_plot.ipynb +++ b/doc/source/tutorials/notebooks/su_summer_days__subset_and_plot.ipynb @@ -129,12 +129,13 @@ "\n", "import cartopy.crs as ccrs\n", "import cftime\n", - "import icclim\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "import pandas as pd\n", "import xarray as xr\n", "\n", + "import icclim\n", + "\n", "print(\"python: \", sys.version)\n", "print(\"numpy: \", np.__version__)\n", "print(\"xarray: \", xr.__version__)\n", diff --git a/doc/source/tutorials/notebooks/tg90p_calculate__subset_and_plot.ipynb b/doc/source/tutorials/notebooks/tg90p_calculate__subset_and_plot.ipynb index fa90e28e..4ab780eb 100644 --- a/doc/source/tutorials/notebooks/tg90p_calculate__subset_and_plot.ipynb +++ b/doc/source/tutorials/notebooks/tg90p_calculate__subset_and_plot.ipynb @@ -133,12 +133,13 @@ "import cartopy.crs as ccrs\n", "import cftime\n", "import dask\n", - "import icclim\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "import pandas as pd\n", "import xarray as xr\n", "\n", + "import icclim\n", + "\n", "print(\"python: \", sys.version)\n", "print(\"numpy: \", np.__version__)\n", "print(\"pandas: \", pd.__version__)\n", diff --git a/src/icclim/_core/generic/threshold/percentile.py b/src/icclim/_core/generic/threshold/percentile.py index 7d1e7660..b7bffd12 100644 --- a/src/icclim/_core/generic/threshold/percentile.py +++ b/src/icclim/_core/generic/threshold/percentile.py @@ -333,7 +333,7 @@ def compute( self.value, op, self.is_doy_per_threshold, - kwargs.get("freq", None), + kwargs.get("freq"), kwargs.get("bootstrap", False), ) msg = ( diff --git a/tests/test_cf_calendar.py b/tests/test_cf_calendar.py index e5980072..d318878c 100644 --- a/tests/test_cf_calendar.py +++ b/tests/test_cf_calendar.py @@ -4,6 +4,7 @@ import pandas as pd import pytest import xarray as xr + from icclim._core.model.cf_calendar import CfCalendarRegistry from icclim.exception import InvalidIcclimArgumentError diff --git a/tests/test_dcsc.py b/tests/test_dcsc.py index 600789f5..fea4ddd8 100644 --- a/tests/test_dcsc.py +++ b/tests/test_dcsc.py @@ -1,5 +1,4 @@ from icclim.dcsc import txnd - from tests.testing_utils import stub_tas diff --git a/tests/test_ecad_indices.py b/tests/test_ecad_indices.py index f0b61c51..39ddd855 100644 --- a/tests/test_ecad_indices.py +++ b/tests/test_ecad_indices.py @@ -1,6 +1,7 @@ from __future__ import annotations import pytest + from icclim._core.model.standard_index import StandardIndex from icclim.ecad.registry import EcadIndexRegistry from icclim.exception import InvalidIcclimArgumentError diff --git a/tests/test_frequency.py b/tests/test_frequency.py index b9ca1901..195fe16d 100644 --- a/tests/test_frequency.py +++ b/tests/test_frequency.py @@ -4,9 +4,9 @@ import numpy as np import pandas as pd import pytest + from icclim.exception import InvalidIcclimArgumentError from icclim.frequency import FrequencyRegistry, get_seasonal_time_updater - from tests.testing_utils import stub_tas diff --git a/tests/test_generated_api.py b/tests/test_generated_api.py index b971e026..42c4307e 100644 --- a/tests/test_generated_api.py +++ b/tests/test_generated_api.py @@ -4,9 +4,10 @@ from typing import TYPE_CHECKING from unittest.mock import MagicMock, patch -import icclim import numpy as np import pytest + +import icclim from icclim._core.constants import QUANTILE_BASED, REFERENCE_PERIOD_INDEX from icclim._core.legacy.user_index.calc_operation import ( CalcOperation, @@ -20,7 +21,6 @@ from icclim.generic.registry import GenericIndicatorRegistry from icclim.logger import VerbosityRegistry from icclim.threshold.factory import build_threshold - from tests.testing_utils import stub_tas if TYPE_CHECKING: @@ -137,7 +137,7 @@ def test_txx__season_slice_mode() -> None: res = icclim.txx(tas, slice_mode=["season", [11, 12, 1, 2]]).compute() # THEN # missing values for nov, dec of first period - np.testing.assert_array_equal(res.TXx.isel(time=0), np.NAN) + np.testing.assert_array_equal(res.TXx.isel(time=0), np.nan) np.testing.assert_array_equal(res.TXx.isel(time=1), 30.0) np.testing.assert_array_equal( res.time_bounds.isel(time=0), @@ -151,7 +151,7 @@ def test_txx__months_slice_mode() -> None: tas.loc[{"time": "2042-01-01"}] = 303.15 # 30°C 273.15 res = icclim.txx(tas, slice_mode=["months", [11, 1]]).compute() np.testing.assert_array_equal(res.TXx.isel(time=0), 30) - np.testing.assert_array_equal(res.TXx.isel(time=1), np.NAN) + np.testing.assert_array_equal(res.TXx.isel(time=1), np.nan) np.testing.assert_almost_equal(res.TXx.sel(time="2042-11"), 21.85) np.testing.assert_array_equal( res.time_bounds.isel(time=0), @@ -192,8 +192,8 @@ def test_custom_index__season_slice_mode( }, ).compute() # missing values algo applied for first and last years - np.testing.assert_almost_equal(res.pouet.isel(time=0), np.NAN) - np.testing.assert_almost_equal(res.pouet.isel(time=-1), np.NAN) + np.testing.assert_almost_equal(res.pouet.isel(time=0), np.nan) + np.testing.assert_almost_equal(res.pouet.isel(time=-1), np.nan) np.testing.assert_almost_equal(res.pouet.isel(time=1), expectation_year_1) np.testing.assert_almost_equal(res.pouet.isel(time=2), expectation_year_2) @@ -225,8 +225,8 @@ def test_custom_index_run_algos__season_slice_mode( }, ) # missing values algo applied for first and last years - np.testing.assert_almost_equal(res.pouet.isel(time=0), np.NAN) - np.testing.assert_almost_equal(res.pouet.isel(time=-1), np.NAN) + np.testing.assert_almost_equal(res.pouet.isel(time=0), np.nan) + np.testing.assert_almost_equal(res.pouet.isel(time=-1), np.nan) np.testing.assert_almost_equal(res.pouet.isel(time=1), expectation_year_1) np.testing.assert_almost_equal(res.pouet.isel(time=2), expectation_year_2) @@ -280,12 +280,12 @@ def test_custom_index_anomaly__datetime_ref_period() -> None: }, ).compute() # missing values algo applied for first and last years - np.testing.assert_almost_equal(res.anomaly.sel(time="2041"), np.NAN) + np.testing.assert_almost_equal(res.anomaly.sel(time="2041"), np.nan) np.testing.assert_almost_equal(res.anomaly.sel(time="2042"), 0) np.testing.assert_almost_equal(res.anomaly.sel(time="2043"), 0) np.testing.assert_almost_equal(res.anomaly.sel(time="2044"), 4.80645161) np.testing.assert_almost_equal(res.anomaly.sel(time="2045"), 0) - np.testing.assert_almost_equal(res.anomaly.sel(time="2046"), np.NAN) + np.testing.assert_almost_equal(res.anomaly.sel(time="2046"), np.nan) def test_custom_index_anomaly__groupby_and_resample_month() -> None: diff --git a/tests/test_generic_functions.py b/tests/test_generic_functions.py index c6961f6a..474eae6b 100644 --- a/tests/test_generic_functions.py +++ b/tests/test_generic_functions.py @@ -4,7 +4,6 @@ from icclim._core.model.standard_variable import StandardVariableRegistry from icclim.frequency import FrequencyRegistry from icclim.threshold.factory import build_threshold - from tests.testing_utils import stub_tas diff --git a/tests/test_index_group.py b/tests/test_index_group.py index 92279e5b..04317296 100644 --- a/tests/test_index_group.py +++ b/tests/test_index_group.py @@ -1,6 +1,7 @@ from __future__ import annotations import pytest + from icclim._core.model.index_group import IndexGroupRegistry from icclim.exception import InvalidIcclimArgumentError diff --git a/tests/test_input_parsing.py b/tests/test_input_parsing.py index e364296a..4a81ae4f 100644 --- a/tests/test_input_parsing.py +++ b/tests/test_input_parsing.py @@ -8,6 +8,7 @@ import pandas as pd import pytest import xarray as xr + from icclim._core.constants import UNITS_KEY from icclim._core.input_parsing import ( PercentileDataArray, diff --git a/tests/test_main.py b/tests/test_main.py index a642c812..3944c3a7 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -6,12 +6,13 @@ from unittest.mock import MagicMock, patch import cftime -import icclim import numpy as np import pandas as pd import pint import pytest import xarray as xr + +import icclim from icclim import __version__ as icclim_version from icclim._core.constants import PART_OF_A_WHOLE_UNIT, REFERENCE_PERIOD_ID, UNITS_KEY from icclim._core.model.index_group import IndexGroupRegistry @@ -19,7 +20,6 @@ from icclim.exception import InvalidIcclimArgumentError from icclim.frequency import FrequencyRegistry from icclim.threshold.factory import build_threshold - from tests.testing_utils import K2C, stub_pr, stub_tas @@ -38,7 +38,7 @@ def test_deprecated_indice(log_mock: MagicMock, index_mock: MagicMock) -> None: HEAT_INDICES = ["SU", "TR", "WSDI", "TG90p", "TN90p", "TX90p", "TXx", "TNx", "CSU"] -@pytest.mark.slow() +@pytest.mark.slow class TestIntegration: """ Integration tests. @@ -282,7 +282,7 @@ def test_index_su__djf_cf_time(self) -> None: out_file=self.OUTPUT_FILE, slice_mode=FrequencyRegistry.DJF, ) - np.testing.assert_array_equal(res.SU.isel(time=0), np.NAN) + np.testing.assert_array_equal(res.SU.isel(time=0), np.nan) np.testing.assert_array_equal(res.SU.isel(time=1), 0) # "+ 1" because DJF sampling create a december month with nans before first year np.testing.assert_array_equal( diff --git a/tests/test_rechunk.py b/tests/test_rechunk.py index 11acc4f9..e666d3db 100644 --- a/tests/test_rechunk.py +++ b/tests/test_rechunk.py @@ -6,6 +6,7 @@ import pandas as pd import pytest import xarray as xr + from icclim import create_optimized_zarr_store from icclim._core.constants import UNITS_KEY from icclim.exception import InvalidIcclimArgumentError diff --git a/tests/test_threshold.py b/tests/test_threshold.py index bc592472..168b8565 100644 --- a/tests/test_threshold.py +++ b/tests/test_threshold.py @@ -9,6 +9,9 @@ import pint import pytest import xarray as xr +from xclim.core.calendar import percentile_doy +from xclim.core.units import units as xc_units + from icclim._core.constants import UNITS_KEY from icclim._core.generic.threshold.basic import BasicThreshold from icclim._core.generic.threshold.bounded import BoundedThreshold @@ -18,8 +21,6 @@ from icclim._core.model.operator import OperatorRegistry from icclim.exception import InvalidIcclimArgumentError from icclim.threshold.factory import build_threshold -from xclim.core.calendar import percentile_doy -from xclim.core.units import units as xc_units def test_value_error() -> None: diff --git a/tests/test_user_index.py b/tests/test_user_index.py index d5d1962a..6f47632e 100644 --- a/tests/test_user_index.py +++ b/tests/test_user_index.py @@ -1,5 +1,7 @@ from __future__ import annotations +from xclim.core.calendar import build_climatology_bounds + import icclim from icclim._core.constants import ( UNITS_KEY, @@ -7,8 +9,6 @@ USER_INDEX_TEMPERATURE_STAMP, ) from icclim._core.model.operator import OperatorRegistry -from xclim.core.calendar import build_climatology_bounds - from tests.testing_utils import stub_tas diff --git a/tests/testing_utils.py b/tests/testing_utils.py index da93a55b..4add35df 100644 --- a/tests/testing_utils.py +++ b/tests/testing_utils.py @@ -3,6 +3,7 @@ import numpy as np import pandas as pd import xarray as xr + from icclim._core.constants import UNITS_KEY VALUE_COUNT = 365 * 5 + 1 # 5 years of data (with 1 leap year) diff --git a/tools/extract_icclim_funs.py b/tools/extract_icclim_funs.py index b1909bdc..b46a9f06 100644 --- a/tools/extract_icclim_funs.py +++ b/tools/extract_icclim_funs.py @@ -27,8 +27,9 @@ from pathlib import Path from typing import TYPE_CHECKING -import icclim from docstring_parser import Docstring, DocstringParam, DocstringStyle, compose, parse + +import icclim from icclim._core.constants import NEEDS_NORMAL, QUANTILE_BASED, REFERENCE_PERIOD_INDEX from icclim._core.generic.threshold.percentile import PercentileThreshold from icclim._core.input_parsing import get_dataarray_from_dataset @@ -47,10 +48,11 @@ if TYPE_CHECKING: from collections.abc import Sequence + from xarray import DataArray, Dataset + from icclim._core.generic.indicator import GenericIndicator from icclim._core.model.registry import Registry from icclim._core.model.standard_index import StandardIndex - from xarray import DataArray, Dataset QUANTILE_INDEX_FIELDS = [ @@ -281,8 +283,8 @@ def {index.name.lower()}( def _normal_index_placeholder( # noqa: ANN202 - normal: str | Sequence[str] | Dataset | DataArray, # noqa: ARG001 - normal_var_name: str | None = None, # noqa: ARG001 + normal: str | Sequence[str] | Dataset | DataArray, + normal_var_name: str | None = None, ): """ Parameters