From daed5c8e947d24be1ddb803e6c8942a5de599d34 Mon Sep 17 00:00:00 2001 From: Andrzej Novak Date: Fri, 23 Feb 2024 18:46:52 +0100 Subject: [PATCH] chore: use ruff for linting (#475) * chore: ruff compatible * chore: use ruff --- .pre-commit-config.yaml | 24 ++++++++---------------- src/mplhep/plot.py | 17 ++++++++++------- src/mplhep/utils.py | 8 +++++--- 3 files changed, 23 insertions(+), 26 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4454a336..af4067b7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -22,18 +22,6 @@ repos: - id: setup-cfg-fmt args: ["--include-version-classifiers", "--max-py-version=3.11"] -- repo: https://github.com/PyCQA/isort - rev: 5.13.2 - hooks: - - id: isort - args: ["-a", "from __future__ import annotations"] - -- repo: https://github.com/asottile/pyupgrade - rev: v3.15.1 - hooks: - - id: pyupgrade - args: ["--py38-plus"] - - repo: https://github.com/nbQA-dev/nbQA rev: 1.7.1 hooks: @@ -46,11 +34,15 @@ repos: hooks: - id: black-jupyter -- repo: https://github.com/PyCQA/flake8 - rev: 7.0.0 +- repo: https://github.com/astral-sh/ruff-pre-commit + # Ruff version. + rev: v0.2.2 hooks: - - id: flake8 - additional_dependencies: [flake8-bugbear] + # Run the linter. + - id: ruff + args: [ --fix ] + # Run the formatter. + - id: ruff-format - repo: https://github.com/pre-commit/mirrors-mypy rev: v1.8.0 diff --git a/src/mplhep/plot.py b/src/mplhep/plot.py index 5ab82762..33fbfef2 100644 --- a/src/mplhep/plot.py +++ b/src/mplhep/plot.py @@ -245,12 +245,14 @@ def histplot( final_bins[0] - _bin_widths[0] * len(_bin_widths) * 0.03, ], ) - value, variance = np.insert(value, 0, np.nan), np.insert( - variance, 0, np.nan + value, variance = ( + np.insert(value, 0, np.nan), + np.insert(variance, 0, np.nan), + ) + value, variance = ( + np.insert(value, 0, h.values(flow=True)[0]), + np.insert(value, 0, h.variances(flow=True)[0]), ) - value, variance = np.insert( - value, 0, h.values(flow=True)[0] - ), np.insert(value, 0, h.variances(flow=True)[0]) if overflow > 0: if i == 0: flow_bins = np.append( @@ -261,8 +263,9 @@ def histplot( ], ) value, variance = np.append(value, np.nan), np.append(variance, np.nan) - value, variance = np.append(value, h.values(flow=True)[-1]), np.append( - variance, h.variances(flow=True)[-1] + value, variance = ( + np.append(value, h.values(flow=True)[-1]), + np.append(variance, h.variances(flow=True)[-1]), ) plottables.append(Plottable(value, edges=flow_bins, variances=variance)) elif flow == "sum": diff --git a/src/mplhep/utils.py b/src/mplhep/utils.py index 3262a526..9437e7d5 100644 --- a/src/mplhep/utils.py +++ b/src/mplhep/utils.py @@ -104,7 +104,8 @@ def _process_histogram_parts_iter( for hist in hists: h = hist_object_handler(hist, *bins) current_bins: tuple[Sequence[float], ...] = tuple( - get_plottable_protocol_bins(a)[0] for a in h.axes # type: ignore[misc] + get_plottable_protocol_bins(a)[0] # type: ignore[misc] + for a in h.axes # type: ignore[misc] ) if any(b is None for b in original_bins): original_bins = current_bins @@ -158,8 +159,9 @@ def __init__(self, values, *, edges=None, variances=None, yerr=None): self.yerr_lo, self.yerr_hi = yerr else: self._errors_present = False - self.yerr_lo, self.yerr_hi = np.zeros_like(self.values), np.zeros_like( - self.values + self.yerr_lo, self.yerr_hi = ( + np.zeros_like(self.values), + np.zeros_like(self.values), ) def __eq__(self, other):