Skip to content

Commit 19d003b

Browse files
authored
chore: use ruff for linting (#475)
* chore: ruff compatible * chore: use ruff
1 parent 280d467 commit 19d003b

File tree

3 files changed

+23
-26
lines changed

3 files changed

+23
-26
lines changed

.pre-commit-config.yaml

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,6 @@ repos:
2222
- id: setup-cfg-fmt
2323
args: ["--include-version-classifiers", "--max-py-version=3.11"]
2424

25-
- repo: https://github.com/PyCQA/isort
26-
rev: 5.13.2
27-
hooks:
28-
- id: isort
29-
args: ["-a", "from __future__ import annotations"]
30-
31-
- repo: https://github.com/asottile/pyupgrade
32-
rev: v3.15.1
33-
hooks:
34-
- id: pyupgrade
35-
args: ["--py38-plus"]
36-
3725
- repo: https://github.com/nbQA-dev/nbQA
3826
rev: 1.7.1
3927
hooks:
@@ -46,11 +34,15 @@ repos:
4634
hooks:
4735
- id: black-jupyter
4836

49-
- repo: https://github.com/PyCQA/flake8
50-
rev: 7.0.0
37+
- repo: https://github.com/astral-sh/ruff-pre-commit
38+
# Ruff version.
39+
rev: v0.2.2
5140
hooks:
52-
- id: flake8
53-
additional_dependencies: [flake8-bugbear]
41+
# Run the linter.
42+
- id: ruff
43+
args: [ --fix ]
44+
# Run the formatter.
45+
- id: ruff-format
5446

5547
- repo: https://github.com/pre-commit/mirrors-mypy
5648
rev: v1.8.0

src/mplhep/plot.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,14 @@ def histplot(
245245
final_bins[0] - _bin_widths[0] * len(_bin_widths) * 0.03,
246246
],
247247
)
248-
value, variance = np.insert(value, 0, np.nan), np.insert(
249-
variance, 0, np.nan
248+
value, variance = (
249+
np.insert(value, 0, np.nan),
250+
np.insert(variance, 0, np.nan),
251+
)
252+
value, variance = (
253+
np.insert(value, 0, h.values(flow=True)[0]),
254+
np.insert(value, 0, h.variances(flow=True)[0]),
250255
)
251-
value, variance = np.insert(
252-
value, 0, h.values(flow=True)[0]
253-
), np.insert(value, 0, h.variances(flow=True)[0])
254256
if overflow > 0:
255257
if i == 0:
256258
flow_bins = np.append(
@@ -261,8 +263,9 @@ def histplot(
261263
],
262264
)
263265
value, variance = np.append(value, np.nan), np.append(variance, np.nan)
264-
value, variance = np.append(value, h.values(flow=True)[-1]), np.append(
265-
variance, h.variances(flow=True)[-1]
266+
value, variance = (
267+
np.append(value, h.values(flow=True)[-1]),
268+
np.append(variance, h.variances(flow=True)[-1]),
266269
)
267270
plottables.append(Plottable(value, edges=flow_bins, variances=variance))
268271
elif flow == "sum":

src/mplhep/utils.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ def _process_histogram_parts_iter(
104104
for hist in hists:
105105
h = hist_object_handler(hist, *bins)
106106
current_bins: tuple[Sequence[float], ...] = tuple(
107-
get_plottable_protocol_bins(a)[0] for a in h.axes # type: ignore[misc]
107+
get_plottable_protocol_bins(a)[0] # type: ignore[misc]
108+
for a in h.axes # type: ignore[misc]
108109
)
109110
if any(b is None for b in original_bins):
110111
original_bins = current_bins
@@ -158,8 +159,9 @@ def __init__(self, values, *, edges=None, variances=None, yerr=None):
158159
self.yerr_lo, self.yerr_hi = yerr
159160
else:
160161
self._errors_present = False
161-
self.yerr_lo, self.yerr_hi = np.zeros_like(self.values), np.zeros_like(
162-
self.values
162+
self.yerr_lo, self.yerr_hi = (
163+
np.zeros_like(self.values),
164+
np.zeros_like(self.values),
163165
)
164166

165167
def __eq__(self, other):

0 commit comments

Comments
 (0)