diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0c884131b..56c460a73 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -33,7 +33,7 @@ repos: - id: yamllint args: [ '--config-file=.yamllint.yaml' ] - repo: https://github.com/psf/black-pre-commit-mirror - rev: 24.4.2 + rev: 24.8.0 hooks: - id: black - repo: https://github.com/PyCQA/isort @@ -41,12 +41,12 @@ repos: hooks: - id: isort - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.5.6 + rev: v0.6.3 hooks: - id: ruff args: [ '--fix' ] - repo: https://github.com/pylint-dev/pylint - rev: v3.2.6 + rev: v3.2.7 hooks: - id: pylint args: [ '--rcfile=.pylintrc.toml', '--errors-only', '--jobs=0', '--disable=import-error' ] @@ -92,7 +92,7 @@ repos: hooks: - id: gitleaks - repo: https://github.com/python-jsonschema/check-jsonschema - rev: 0.29.1 + rev: 0.29.2 hooks: - id: check-github-workflows - id: check-readthedocs diff --git a/docs/notebooks/analogs.ipynb b/docs/notebooks/analogs.ipynb index 2c53f01a8..06603902b 100644 --- a/docs/notebooks/analogs.ipynb +++ b/docs/notebooks/analogs.ipynb @@ -142,6 +142,7 @@ "\n", "\n", "def plot_best_analog(scores, ax=None):\n", + " \"\"\"Plot the best analog on the map.\"\"\"\n", " scores1d = scores.stack(site=[\"lon\", \"lat\"])\n", " lon, lat = scores1d.isel(site=scores1d.argmin(\"site\")).site.item()\n", " ax = ax or plt.gca()\n", diff --git a/docs/notebooks/benchmarks/sdba_quantile.ipynb b/docs/notebooks/benchmarks/sdba_quantile.ipynb index ce19b230c..67823e0ab 100644 --- a/docs/notebooks/benchmarks/sdba_quantile.ipynb +++ b/docs/notebooks/benchmarks/sdba_quantile.ipynb @@ -12,7 +12,6 @@ "\n", "import numpy as np\n", "\n", - "import xclim\n", "from xclim import sdba\n", "from xclim.testing import open_dataset\n", "\n", @@ -90,8 +89,6 @@ "metadata": {}, "outputs": [], "source": [ - "import time\n", - "\n", "import matplotlib.pyplot as plt\n", "import xarray as xr\n", "\n", diff --git a/docs/notebooks/customize.ipynb b/docs/notebooks/customize.ipynb index 1b1ed7a51..d9d8ab0ef 100644 --- a/docs/notebooks/customize.ipynb +++ b/docs/notebooks/customize.ipynb @@ -174,10 +174,12 @@ " \"\"\"Any period with more than max_n consecutive missing values is considered invalid\"\"\"\n", "\n", " def is_missing(self, null, count, max_n=5):\n", + " \"\"\"Return a boolean mask where True values are for elements that are considered missing and masked on the output.\"\"\"\n", " return null.map(longest_run, dim=\"time\") >= max_n\n", "\n", " @staticmethod\n", " def validate(max_n):\n", + " \"\"\"Return whether the options are valid.\"\"\"\n", " return max_n > 0" ] }, diff --git a/docs/notebooks/ensembles-advanced.ipynb b/docs/notebooks/ensembles-advanced.ipynb index 572da5910..394bb25d0 100644 --- a/docs/notebooks/ensembles-advanced.ipynb +++ b/docs/notebooks/ensembles-advanced.ipynb @@ -297,7 +297,7 @@ "metadata": {}, "outputs": [], "source": [ - "## NESTED results using KKZ\n", + "# NESTED results using KKZ\n", "for n in np.arange(5, 15, 3):\n", " ids = ensembles.kkz_reduce_ensemble(crit, num_select=n)\n", " print(ids)" @@ -313,7 +313,7 @@ }, "outputs": [], "source": [ - "## UNNESTED results using k-means\n", + "# UNNESTED results using k-means\n", "for n in np.arange(5, 15, 3):\n", " ids, cluster, fig_data = ensembles.kmeans_reduce_ensemble(\n", " crit, method={\"n_clusters\": n}, random_state=42, make_graph=True\n", diff --git a/docs/notebooks/ensembles.ipynb b/docs/notebooks/ensembles.ipynb index 381b3af14..737d5985b 100644 --- a/docs/notebooks/ensembles.ipynb +++ b/docs/notebooks/ensembles.ipynb @@ -155,16 +155,15 @@ }, "outputs": [], "source": [ - "import xarray as xr\n", - "\n", - "# Set display to HTML style (for fancy output)\n", - "xr.set_options(display_style=\"html\", display_width=50)\n", - "\n", "import matplotlib as mpl\n", "import matplotlib.pyplot as plt\n", + "import xarray as xr\n", "\n", "from xclim import ensembles\n", "\n", + "# Set display to HTML style (for fancy output)\n", + "xr.set_options(display_style=\"html\", display_width=50)\n", + "\n", "%matplotlib inline\n", "\n", "ens = ensembles.create_ensemble(data_folder.glob(\"ens_tas_m*.nc\")).load()\n", diff --git a/docs/notebooks/example.ipynb b/docs/notebooks/example.ipynb index cb237befd..21c913684 100644 --- a/docs/notebooks/example.ipynb +++ b/docs/notebooks/example.ipynb @@ -36,19 +36,18 @@ }, "outputs": [], "source": [ - "from __future__ import annotations\n", + "from __future__ import annotations # noqa: F404\n", "\n", - "# File handling libraries\n", "import tempfile\n", "from pathlib import Path\n", "\n", "import xarray as xr\n", "\n", + "import xclim.indices\n", + "\n", "# Set xarray to use HTML for displaying outputs\n", "xr.set_options(display_style=\"html\")\n", "\n", - "import xclim.indices\n", - "\n", "# Output folder\n", "output_folder = Path(tempfile.mkdtemp())" ] @@ -174,7 +173,7 @@ }, "outputs": [], "source": [ - "## Create multi-file data & chunks\n", + "# Create multi-file data & chunks\n", "# ds = xr.open_mfdataset('/path/to/files*.nc')" ] }, diff --git a/docs/notebooks/extendxclim.ipynb b/docs/notebooks/extendxclim.ipynb index d6ef80233..8293e3ba5 100644 --- a/docs/notebooks/extendxclim.ipynb +++ b/docs/notebooks/extendxclim.ipynb @@ -11,7 +11,7 @@ "# Workaround for determining the notebook folder within a running notebook\n", "# This cell is not visible when the documentation is built.\n", "\n", - "from __future__ import annotations\n", + "from __future__ import annotations # noqa: F404\n", "\n", "try:\n", " from _finder import _find_current_folder\n", @@ -92,8 +92,6 @@ "metadata": {}, "outputs": [], "source": [ - "from __future__ import annotations\n", - "\n", "import xarray as xr\n", "from IPython.display import Code, display\n", "\n", diff --git a/docs/notebooks/partitioning.ipynb b/docs/notebooks/partitioning.ipynb index a6c8d7100..d50665004 100644 --- a/docs/notebooks/partitioning.ipynb +++ b/docs/notebooks/partitioning.ipynb @@ -181,7 +181,7 @@ " mpl.axes.Axes\n", " \"\"\"\n", " if ax is None:\n", - " fig, ax = plt.subplots(1, 1)\n", + " _, ax = plt.subplots(1, 1)\n", "\n", " # Compute fraction\n", " da = variance / variance.sel(uncertainty=\"total\") * 100\n", diff --git a/docs/notebooks/sdba-advanced.ipynb b/docs/notebooks/sdba-advanced.ipynb index 2c214c9a3..0e7b32e32 100644 --- a/docs/notebooks/sdba-advanced.ipynb +++ b/docs/notebooks/sdba-advanced.ipynb @@ -83,7 +83,7 @@ "ax.set_xlabel(\"Time\")\n", "ax.set_ylabel(\"Temperature [K]\")\n", "\n", - "## The code below calls internal functions to demonstrate how the weights are computed.\n", + "# The code below calls internal functions to demonstrate how the weights are computed.\n", "\n", "# LOESS algorithms as implemented here use scaled coordinates.\n", "x = tas.time\n", diff --git a/docs/notebooks/units.ipynb b/docs/notebooks/units.ipynb index 014180b8a..9b0ea7ed6 100644 --- a/docs/notebooks/units.ipynb +++ b/docs/notebooks/units.ipynb @@ -15,6 +15,8 @@ "source": [ "from __future__ import annotations\n", "\n", + "import matplotlib.pyplot as plt\n", + "import nc_time_axis # noqa\n", "import xarray as xr\n", "\n", "import xclim\n", @@ -24,10 +26,6 @@ "# Set display to HTML style (optional)\n", "xr.set_options(display_style=\"html\", display_width=50)\n", "\n", - "# import plotting stuff\n", - "import matplotlib.pyplot as plt\n", - "import nc_time_axis # noqa\n", - "\n", "%matplotlib inline\n", "plt.rcParams[\"figure.figsize\"] = (11, 5)" ] diff --git a/docs/notebooks/xclim_training/Exercices.ipynb b/docs/notebooks/xclim_training/Exercices.ipynb index abdd32d61..736731b14 100644 --- a/docs/notebooks/xclim_training/Exercices.ipynb +++ b/docs/notebooks/xclim_training/Exercices.ipynb @@ -51,8 +51,6 @@ "\n", "import xarray as xr\n", "\n", - "from xclim.testing import ope\n", - "\n", "# Pour ouvrir tous les mois d'une année:\n", "ds = xr.open_mfdataset(\"/tas_bch_2032??_se.nc\")" ] diff --git a/docs/notebooks/xclim_training/XCLIM Demo - Ensembles.ipynb b/docs/notebooks/xclim_training/XCLIM Demo - Ensembles.ipynb index e8d1bfd98..bf665d85b 100644 --- a/docs/notebooks/xclim_training/XCLIM Demo - Ensembles.ipynb +++ b/docs/notebooks/xclim_training/XCLIM Demo - Ensembles.ipynb @@ -26,11 +26,9 @@ "mpl_logger = logging.getLogger(\"matplotlib\")\n", "mpl_logger.setLevel(logging.WARNING)\n", "\n", - "import dask\n", "\n", "# XCLIM and xarray\n", "import numpy as np\n", - "import xarray as xr\n", "from distributed import Client" ] }, diff --git a/docs/notebooks/xclim_training/XCLIM_calculate_index-Exemple.ipynb b/docs/notebooks/xclim_training/XCLIM_calculate_index-Exemple.ipynb index a5e055d0b..31fe82dde 100644 --- a/docs/notebooks/xclim_training/XCLIM_calculate_index-Exemple.ipynb +++ b/docs/notebooks/xclim_training/XCLIM_calculate_index-Exemple.ipynb @@ -28,8 +28,6 @@ "import time\n", "from pathlib import Path\n", "\n", - "import dask\n", - "import numpy as np\n", "import xarray as xr\n", "\n", "import xclim.atmos as atmos\n", diff --git a/docs/notebooks/xclim_training/readme.ipynb b/docs/notebooks/xclim_training/readme.ipynb index 68b657244..9f89f0521 100644 --- a/docs/notebooks/xclim_training/readme.ipynb +++ b/docs/notebooks/xclim_training/readme.ipynb @@ -93,7 +93,7 @@ "metadata": {}, "outputs": [], "source": [ - "$ ps aux | grep localhost \n", + "$ ps aux | grep localhost\n", "$ kill -9 " ] } diff --git a/pyproject.toml b/pyproject.toml index 4075f4bab..2c616fe95 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -289,6 +289,9 @@ extend-include = [ line-ending = "auto" [tool.ruff.lint] +exclude = [ + "docs/notebooks/xclim_training/*.ipynb" +] extend-select = [ "RUF022" # unsorted-dunder-all ] @@ -331,6 +334,7 @@ max-complexity = 20 [tool.ruff.lint.per-file-ignores] "docs/*.py" = ["D100", "D101", "D102", "D103"] +"docs/notebooks/*.ipynb" = ["E225", "E226", "E231"] "tests/**/*test*.py" = ["D100", "D101", "D102", "D103", "N802", "S101"] "xclim/**/__init__.py" = ["F401", "F403"] "xclim/core/indicator.py" = ["D214", "D405", "D406", "D407", "D411"]