From a7f01eb2e76aac1359cf8a68daceb3660086a815 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 13 Feb 2024 10:57:32 -0800 Subject: [PATCH] [pre-commit.ci] pre-commit autoupdate (#434) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [pre-commit.ci] pre-commit autoupdate updates: - [github.com/pre-commit/pre-commit-hooks: v4.4.0 → v4.5.0](https://github.com/pre-commit/pre-commit-hooks/compare/v4.4.0...v4.5.0) - [github.com/psf/black: 23.3.0 → 24.2.0](https://github.com/psf/black/compare/23.3.0...24.2.0) - https://github.com/charliermarsh/ruff-pre-commit → https://github.com/astral-sh/ruff-pre-commit - [github.com/astral-sh/ruff-pre-commit: v0.0.269 → v0.2.1](https://github.com/astral-sh/ruff-pre-commit/compare/v0.0.269...v0.2.1) - [github.com/nbQA-dev/nbQA: 1.7.0 → 1.7.1](https://github.com/nbQA-dev/nbQA/compare/1.7.0...1.7.1) - [github.com/pre-commit/mirrors-mypy: v1.3.0 → v1.8.0](https://github.com/pre-commit/mirrors-mypy/compare/v1.3.0...v1.8.0) * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Pre commit fixes --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Bas Nijholt --- .pre-commit-config.yaml | 12 ++++++------ adaptive/learner/average_learner1D.py | 7 ++++--- adaptive/learner/integrator_learner.py | 1 - adaptive/learner/learner1D.py | 12 +++++++----- adaptive/learner/learnerND.py | 8 +++++--- adaptive/runner.py | 6 +++--- pyproject.toml | 8 +++++--- 7 files changed, 30 insertions(+), 24 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6c10c533e..2405489e1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer @@ -9,16 +9,16 @@ repos: - id: debug-statements - id: check-ast - repo: https://github.com/psf/black - rev: 23.3.0 + rev: 24.2.0 hooks: - id: black-jupyter - - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: "v0.0.269" + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: "v0.2.1" hooks: - id: ruff args: ["--fix"] - repo: https://github.com/nbQA-dev/nbQA - rev: 1.7.0 + rev: 1.7.1 hooks: - id: nbqa-black additional_dependencies: [jupytext, black] @@ -26,7 +26,7 @@ repos: args: ["ruff", "--fix", "--ignore=E402,B018,F704"] additional_dependencies: [jupytext, ruff] - repo: https://github.com/pre-commit/mirrors-mypy - rev: "v1.3.0" + rev: "v1.8.0" hooks: - id: mypy exclude: ipynb_filter.py|docs/source/conf.py diff --git a/adaptive/learner/average_learner1D.py b/adaptive/learner/average_learner1D.py index 12c7c9a6c..5dc9097ba 100644 --- a/adaptive/learner/average_learner1D.py +++ b/adaptive/learner/average_learner1D.py @@ -79,8 +79,9 @@ def __init__( self, function: Callable[[tuple[int, Real]], Real], bounds: tuple[Real, Real], - loss_per_interval: None - | (Callable[[Sequence[Real], Sequence[Real]], float]) = None, + loss_per_interval: None | ( + Callable[[Sequence[Real], Sequence[Real]], float] + ) = None, delta: float = 0.2, alpha: float = 0.005, neighbor_sampling: float = 0.3, @@ -310,7 +311,7 @@ def _ask_for_new_point(self, n: int) -> tuple[Points, list[float]]: new point, since in general n << min_samples and this point will need to be resampled many more times""" points, (loss_improvement,) = self._ask_points_without_adding(1) - seed_points = [(seed, x) for seed, x in zip(range(n), n * points)] + seed_points = list(zip(range(n), n * points)) loss_improvements = [loss_improvement / n] * n return seed_points, loss_improvements # type: ignore[return-value] diff --git a/adaptive/learner/integrator_learner.py b/adaptive/learner/integrator_learner.py index 74aebe1ca..0fc97df67 100644 --- a/adaptive/learner/integrator_learner.py +++ b/adaptive/learner/integrator_learner.py @@ -71,7 +71,6 @@ class DivergentIntegralError(ValueError): class _Interval: - """ Attributes ---------- diff --git a/adaptive/learner/learner1D.py b/adaptive/learner/learner1D.py index 8385e67b8..bf04743bd 100644 --- a/adaptive/learner/learner1D.py +++ b/adaptive/learner/learner1D.py @@ -135,7 +135,7 @@ def triangle_loss(xs: XsType1, ys: YsType1) -> Float: pts = [(x, *y) for x, y in zip(xs, ys)] # type: ignore[misc] vol = simplex_volume_in_embedding else: - pts = [(x, y) for x, y in zip(xs, ys)] + pts = list(zip(xs, ys)) vol = volume return sum(vol(pts[i : i + 3]) for i in range(N)) / N @@ -633,10 +633,12 @@ def tell_pending(self, x: float) -> None: def tell_many( self, xs: Sequence[Float] | np.ndarray, - ys: Sequence[Float] - | Sequence[Sequence[Float]] - | Sequence[np.ndarray] - | np.ndarray, + ys: ( + Sequence[Float] + | Sequence[Sequence[Float]] + | Sequence[np.ndarray] + | np.ndarray + ), *, force: bool = False, ) -> None: diff --git a/adaptive/learner/learnerND.py b/adaptive/learner/learnerND.py index edc839d8d..c8eacea2f 100644 --- a/adaptive/learner/learnerND.py +++ b/adaptive/learner/learnerND.py @@ -987,9 +987,11 @@ def plot_slice(self, cut_mapping, n=None): xs = ys = np.linspace(0, 1, n) xys = [xs[:, None], ys[None, :]] values = [ - cut_mapping[i] - if i in cut_mapping - else xys.pop(0) * (b[1] - b[0]) + b[0] + ( + cut_mapping[i] + if i in cut_mapping + else xys.pop(0) * (b[1] - b[0]) + b[0] + ) for i, b in enumerate(self._bbox) ] diff --git a/adaptive/runner.py b/adaptive/runner.py index 644433516..58abc7139 100644 --- a/adaptive/runner.py +++ b/adaptive/runner.py @@ -470,7 +470,7 @@ def __init__( npoints_goal: int | None = None, end_time_goal: datetime | None = None, duration_goal: timedelta | int | float | None = None, - executor: (ExecutorTypes | None) = None, + executor: ExecutorTypes | None = None, ntasks: int | None = None, log: bool = False, shutdown_executor: bool = False, @@ -629,7 +629,7 @@ def __init__( npoints_goal: int | None = None, end_time_goal: datetime | None = None, duration_goal: timedelta | int | float | None = None, - executor: (ExecutorTypes | None) = None, + executor: ExecutorTypes | None = None, ntasks: int | None = None, log: bool = False, shutdown_executor: bool = False, @@ -956,7 +956,7 @@ def _ensure_executor(executor: ExecutorTypes | None) -> concurrent.Executor: def _get_ncores( - ex: (ExecutorTypes), + ex: ExecutorTypes, ) -> int: """Return the maximum number of cores that an executor can use.""" if with_ipyparallel: diff --git a/pyproject.toml b/pyproject.toml index f0ea8eddf..1cdc34dfd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -97,6 +97,8 @@ python_version = "3.9" [tool.ruff] line-length = 150 target-version = "py39" + +[tool.ruff.lint] select = ["B", "C", "E", "F", "W", "T", "B9", "I", "UP"] ignore = [ "T20", # flake8-print @@ -109,14 +111,14 @@ ignore = [ "D401", # First line of docstring should be in imperative mood ] +[tool.ruff.lint.mccabe] +max-complexity = 18 + [tool.ruff.per-file-ignores] "tests/*" = ["SLF001"] "ci/*" = ["INP001"] "tests/test_examples.py" = ["E501"] -[tool.ruff.mccabe] -max-complexity = 18 - [tool.versioningit] [tool.versioningit.vcs]