Skip to content

Commit

Permalink
Merge branch 'main' into pylint-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeitsperre authored Sep 3, 2024
2 parents 8719d84 + de8b8b8 commit faec7d4
Show file tree
Hide file tree
Showing 16 changed files with 27 additions and 35 deletions.
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,20 @@ 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
rev: 5.13.2
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' ]
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions docs/notebooks/analogs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 0 additions & 3 deletions docs/notebooks/benchmarks/sdba_quantile.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -90,8 +89,6 @@
"metadata": {},
"outputs": [],
"source": [
"import time\n",
"\n",
"import matplotlib.pyplot as plt\n",
"import xarray as xr\n",
"\n",
Expand Down
2 changes: 2 additions & 0 deletions docs/notebooks/customize.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
},
Expand Down
4 changes: 2 additions & 2 deletions docs/notebooks/ensembles-advanced.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand All @@ -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",
Expand Down
9 changes: 4 additions & 5 deletions docs/notebooks/ensembles.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 4 additions & 5 deletions docs/notebooks/example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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())"
]
Expand Down Expand Up @@ -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')"
]
},
Expand Down
4 changes: 1 addition & 3 deletions docs/notebooks/extendxclim.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion docs/notebooks/partitioning.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion docs/notebooks/sdba-advanced.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 2 additions & 4 deletions docs/notebooks/units.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)"
]
Expand Down
2 changes: 0 additions & 2 deletions docs/notebooks/xclim_training/Exercices.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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(\"<path_to_file>/tas_bch_2032??_se.nc\")"
]
Expand Down
2 changes: 0 additions & 2 deletions docs/notebooks/xclim_training/XCLIM Demo - Ensembles.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion docs/notebooks/xclim_training/readme.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"metadata": {},
"outputs": [],
"source": [
"$ ps aux | grep localhost \n",
"$ ps aux | grep localhost\n",
"$ kill -9 <PID du process correspondant>"
]
}
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ extend-include = [
line-ending = "auto"

[tool.ruff.lint]
exclude = [
"docs/notebooks/xclim_training/*.ipynb"
]
extend-select = [
"RUF022" # unsorted-dunder-all
]
Expand Down Expand Up @@ -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"]
Expand Down

0 comments on commit faec7d4

Please sign in to comment.