Skip to content

Commit 46e27a8

Browse files
Update and apply Pre-Commit hooks (#134)
1 parent 471abb3 commit 46e27a8

File tree

11 files changed

+62
-49
lines changed

11 files changed

+62
-49
lines changed

.pre-commit-config.yaml

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright (C) 2023 Benjamin Thomas Schwertfeger
3+
# GitHub: https://github.com/btschwertfeger
4+
#
5+
16
repos:
27
- repo: https://github.com/astral-sh/ruff-pre-commit
3-
rev: v0.4.9
8+
rev: v0.7.0
49
hooks:
510
- id: ruff
6-
args: [--fix]
11+
args:
12+
- --fix
13+
- --preview
14+
- --exit-non-zero-on-fix
715
- id: ruff-format
8-
- repo: https://github.com/pycqa/flake8
9-
rev: 7.1.0
10-
hooks:
11-
- id: flake8
12-
args: ["--select=E9,F63,F7,F82", "--show-source", "--statistics"]
1316
# - repo: https://github.com/pre-commit/mirrors-mypy # FIXME
14-
# rev: v1.8.0
17+
# rev: v1.13.0
1518
# hooks:
1619
# - id: mypy
1720
# name: mypy
@@ -23,14 +26,14 @@ repos:
2326
rev: v2.3.0
2427
hooks:
2528
- id: codespell
26-
additional_dependencies:
27-
- tomli
29+
additional_dependencies: [tomli]
2830
- repo: https://github.com/pre-commit/pre-commit-hooks
2931
rev: v4.6.0
3032
hooks:
3133
# all available hooks can be found here: https://github.com/pre-commit/pre-commit-hooks/blob/main/.pre-commit-hooks.yaml
3234
- id: check-yaml
3335
- id: check-ast
36+
- id: check-json
3437
- id: check-toml
3538
- id: check-docstring-first
3639
- id: check-case-conflict
@@ -53,26 +56,32 @@ repos:
5356
rev: v1.10.0
5457
hooks:
5558
- id: python-use-type-annotations
59+
- id: python-check-blanket-noqa
60+
- id: python-check-blanket-type-ignore
61+
- id: python-check-mock-methods
62+
- id: rst-backticks
63+
- id: python-no-eval
64+
- id: python-no-log-warn
5665
- id: rst-backticks
57-
# - id: rst-inline-touching-normal
66+
- id: rst-inline-touching-normal
5867
- id: rst-directive-colons
5968
- id: text-unicode-replacement-char
60-
# - repo: https://github.com/psf/black
61-
# rev: 24.2.0
62-
# hooks:
63-
# - id: black
64-
# - repo: https://github.com/adamchainz/blacken-docs
65-
# rev: 1.16.0
66-
# hooks:
67-
# - id: blacken-docs
68-
# additional_dependencies: [black==23.12.0]
6969
- repo: https://github.com/PyCQA/isort # TODO: remove as soon as ruff is stable
7070
rev: 5.13.2
7171
hooks:
7272
- id: isort
73-
args: ["--profile=black"] # solves conflicts between black and isort
74-
- repo: https://github.com/pre-commit/mirrors-prettier
75-
rev: v3.0.2
73+
args: [--profile=black]
74+
- repo: https://github.com/PyCQA/bandit
75+
rev: 1.7.10
76+
hooks:
77+
- id: bandit
78+
exclude: "^tests/.*|examples/.*"
79+
- repo: https://github.com/yunojuno/pre-commit-xenon
80+
rev: v0.1
7681
hooks:
77-
- id: prettier
82+
- id: xenon
83+
args:
84+
- --max-average=B
85+
- --max-modules=B
86+
- --max-absolute=C
7887
exclude: '\.nc$|^tests/fixture/|\.ipynb$'

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,13 @@ Notes:
293293

294294
- First check if there is an existing issue or PR that addresses your
295295
problem/solution. If not - create one first - before creating a PR.
296-
- Typo fixes, project configuration, CI, documentation or style/formatting PRs will be
297-
rejected. Please create an issue for that.
296+
- Typo fixes, project configuration, CI, documentation or style/formatting PRs
297+
will be rejected. Please create an issue for that.
298298
- PRs must provide a reasonable, easy to understand and maintain solution for an
299299
existing problem. You may want to propose a solution when creating the issue
300300
to discuss the approach before creating a PR.
301+
- There is currently no need for the implementation of further bias correction
302+
methods.
301303

302304
<a name="references"></a>
303305

cmethods/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def print_version(
5353
"""Prints the version of the package"""
5454
if not value or ctx.resilient_parsing:
5555
return
56-
from importlib.metadata import version
56+
from importlib.metadata import version # noqa: PLC0415
5757

5858
echo(version("python-cmethods"))
5959
ctx.exit()

cmethods/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def adjust(
144144
# to unrealistic monthly transitions. If such behavior is wanted,
145145
# mock this function or apply ``CMethods.__apply_ufunc` directly
146146
# on your data sets.
147-
if kwargs.get("group", None) is None:
147+
if kwargs.get("group") is None:
148148
return apply_ufunc(method, obs, simh, simp, **kwargs).to_dataset()
149149

150150
if method not in SCALING_METHODS:

cmethods/distribution.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def quantile_mapping(
4242
"""
4343
check_adjust_called(
4444
function_name="quantile_mapping",
45-
adjust_called=kwargs.get("adjust_called", None),
45+
adjust_called=kwargs.get("adjust_called"),
4646
)
4747
check_np_types(obs=obs, simh=simh, simp=simp)
4848

@@ -73,7 +73,7 @@ def quantile_mapping(
7373
xbins,
7474
cdf_simh,
7575
left=kwargs.get("val_min", 0.0),
76-
right=kwargs.get("val_max", None),
76+
right=kwargs.get("val_max"),
7777
)
7878
return get_inverse_of_cdf(cdf_obs, epsilon, xbins) # Eq. 2
7979

@@ -157,7 +157,7 @@ def detrended_quantile_mapping(
157157
xbins,
158158
cdf_simh,
159159
left=kwargs.get("val_min", 0.0),
160-
right=kwargs.get("val_max", None),
160+
right=kwargs.get("val_max"),
161161
)
162162
X = np.interp(epsilon, cdf_obs, xbins) * ensure_dividable(
163163
m_simp_mean,
@@ -205,7 +205,7 @@ def quantile_delta_mapping(
205205
"""
206206
check_adjust_called(
207207
function_name="quantile_delta_mapping",
208-
adjust_called=kwargs.get("adjust_called", None),
208+
adjust_called=kwargs.get("adjust_called"),
209209
)
210210
check_np_types(obs=obs, simh=simh, simp=simp)
211211

cmethods/scaling.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def linear_scaling(
4343
"""
4444
check_adjust_called(
4545
function_name="linear_scaling",
46-
adjust_called=kwargs.get("adjust_called", None),
46+
adjust_called=kwargs.get("adjust_called"),
4747
)
4848
check_np_types(obs=obs, simh=simh, simp=simp)
4949

@@ -85,7 +85,7 @@ def variance_scaling(
8585
"""
8686
check_adjust_called(
8787
function_name="variance_scaling",
88-
adjust_called=kwargs.get("adjust_called", None),
88+
adjust_called=kwargs.get("adjust_called"),
8989
)
9090
check_np_types(obs=obs, simh=simp, simp=simp)
9191

@@ -130,7 +130,7 @@ def delta_method(
130130
"""
131131
check_adjust_called(
132132
function_name="delta_method",
133-
adjust_called=kwargs.get("adjust_called", None),
133+
adjust_called=kwargs.get("adjust_called"),
134134
)
135135
check_np_types(obs=obs, simh=simh, simp=simp)
136136

cmethods/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def __init__(self: UnknownMethodError, method: str, available_methods: list):
3232

3333
def check_adjust_called(
3434
function_name: str,
35-
adjust_called: Optional[bool] = None,
35+
adjust_called: Optional[bool] = None, # noqa: FBT001
3636
) -> None:
3737
"""
3838
Displays a user warning in case a correction function was not called via

doc/conf.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
"""This module is the configuration for the Sphinx documentation building process"""
1212

1313
import sys
14+
from os.path import join
1415
from pathlib import Path
16+
from shutil import copyfile
1517

1618
project = "python-cmethods"
1719
copyright = "2023, Benjamin Thomas Schwertfeger" # pylint: disable=redefined-builtin
@@ -29,9 +31,6 @@
2931

3032

3133
def setup(app) -> None: # noqa: ARG001
32-
from os.path import join
33-
from shutil import copyfile
34-
3534
copyfile(join("..", "examples", "examples.ipynb"), "examples.ipynb")
3635

3736

doc/methods.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ where:
9292
>>> variable = "tas" # temperatures
9393
>>> result = adjust(
9494
... method="linear_scaling",
95-
... obs=obs[variable],
95+
... obs=obsh[variable],
9696
... simh=simh[variable],
9797
... simp=simp[variable],
9898
... kind="+",
@@ -173,7 +173,7 @@ enables the adjustment of the standard deviation in the following step.
173173
>>> variable = "tas" # temperatures
174174
>>> result = adjust(
175175
... method="variance_scaling",
176-
... obs=obs[variable],
176+
... obs=obsh[variable],
177177
... simh=simh[variable],
178178
... simp=simp[variable],
179179
... kind="+",
@@ -257,7 +257,7 @@ where:
257257
>>> variable = "tas" # temperatures
258258
>>> result = adjust(
259259
... method="delta_method",
260-
... obs=obs[variable],
260+
... obs=obsh[variable],
261261
... simh=simh[variable],
262262
... simp=simp[variable],
263263
... kind="+",
@@ -340,7 +340,7 @@ In the following the equations of Alex J. Cannon (2015) are shown and explained:
340340
>>> variable = "tas" # temperatures
341341
>>> qm_adjusted = adjust(
342342
... method="quantile_mapping",
343-
... obs=obs[variable],
343+
... obs=obsh[variable],
344344
... simh=simh[variable],
345345
... simp=simp[variable],
346346
... n_quantiles=250,
@@ -417,7 +417,7 @@ where:
417417
>>> simp = xr.open_dataset("path/to/the_dataset_to_adjust-scenario_period.nc")
418418
>>> variable = "tas" # temperatures
419419
>>> qm_adjusted = detrended_quantile_mapping(
420-
... obs=obs[variable],
420+
... obs=obsh[variable],
421421
... simh=simh[variable],
422422
... simp=simp[variable],
423423
... n_quantiles=250
@@ -520,7 +520,7 @@ following the additive and multiplicative variant are shown.
520520
>>> variable = "tas" # temperatures
521521
>>> qdm_adjusted = adjust(
522522
... method="quantile_delta_mapping",
523-
... obs=obs[variable],
523+
... obs=obsh[variable],
524524
... simh=simh[variable],
525525
... simp=simp[variable],
526526
... n_quantiles=250,

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,11 @@ cache-dir = ".cache/ruff"
250250
lint.task-tags = ["todo", "TODO"]
251251

252252
[tool.ruff.lint.per-file-ignores]
253+
"cmethods/types.py" = [
254+
"A005", # Shadowing builtin
255+
]
253256
"doc/*.py" = [
254-
"CPY001", # Missing copyright notice at top of file
257+
# "CPY001", # Missing copyright notice at top of file
255258
"PTH118", # `os.path.join()` should be replaced by `Path` with `/` operator,
256259
"PTH123", # `open()` should be replaced by `Path.open()`
257260
"PTH100", # `os.path.abspath()` should be replaced by `Path.resolve()`

tests/conftest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
FIXTURE_DIR: str = os.path.join(os.path.dirname(__file__), "fixture")
2323

2424

25-
@pytest.fixture()
25+
@pytest.fixture
2626
def cli_runner() -> CliRunner:
2727
"""Provide a cli-runner for testing the CLI"""
2828
return CliRunner()
@@ -43,7 +43,7 @@ def dask_cluster() -> Any:
4343
client.close()
4444

4545

46-
@pytest.fixture()
46+
@pytest.fixture
4747
def datasets() -> dict:
4848
obsh_add, obsp_add, simh_add, simp_add = get_datasets(kind="+")
4949
obsh_mult, obsp_mult, simh_mult, simp_mult = get_datasets(kind="*")
@@ -65,7 +65,7 @@ def datasets() -> dict:
6565

6666

6767
@lru_cache(maxsize=None)
68-
@pytest.fixture()
68+
@pytest.fixture
6969
def datasets_from_zarr() -> dict:
7070
return {
7171
"+": {

0 commit comments

Comments
 (0)