Skip to content

Commit

Permalink
chore: use ruff for linting (#475)
Browse files Browse the repository at this point in the history
* chore: ruff compatible

* chore: use ruff
  • Loading branch information
andrzejnovak authored and jonas-eschle committed Apr 22, 2024
1 parent 583ee0f commit daed5c8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 26 deletions.
24 changes: 8 additions & 16 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
17 changes: 10 additions & 7 deletions src/mplhep/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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":
Expand Down
8 changes: 5 additions & 3 deletions src/mplhep/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit daed5c8

Please sign in to comment.