Skip to content

Commit

Permalink
Updating ruff (#241)
Browse files Browse the repository at this point in the history
* update linter versions

* update line length from 88 to 100

* lint

* changelog

* fix

* fix

* fix

* cleanup

* fix

* show fix

* coverage

* fix

* fix
  • Loading branch information
samvanstroud authored Feb 26, 2024
1 parent 6b2361f commit a0f8edf
Show file tree
Hide file tree
Showing 59 changed files with 609 additions and 1,011 deletions.
1 change: 1 addition & 0 deletions .github/workflows/github_update_todo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Checks repository in main and prints the content for a ToDo issue."""

from __future__ import annotations

from pylint import epylint as lint
Expand Down
16 changes: 8 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
repos:
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.1.6"
rev: "v0.2.2"
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
args: [--fix, --show-fixes, --exit-non-zero-on-fix]
- id: ruff-format

- repo: https://github.com/adrienverge/yamllint.git
rev: v1.32.0
hooks:
- id: yamllint
args: ["-d", "{extends: relaxed, rules: {line-length: disable}}"]

#- repo: https://github.com/pre-commit/mirrors-mypy
# rev: "v1.1.1"
# hooks:
# - id: mypy
# args: [--ignore-missing-imports]
# additional_dependencies: ["types-requests", "types-PyYAML"]

#- repo: https://github.com/adrienverge/yamllint.git
# rev: v1.17.0
# hooks:
# - id: yamllint
# args: ["-d", "{extends: relaxed, rules: {line-length: disable}}"]
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

### [Latest]
- Update ruff [!241](https://github.com/umami-hep/puma/pull/241)
- Extend ftau support and remove discriminant code [!240](https://github.com/umami-hep/puma/pull/240)
- Fix ROC x-range config for yuma [!239](https://github.com/umami-hep/puma/pull/239)
- Allow for base dir Yuma loading [!238](https://github.com/umami-hep/puma/pull/238)
Expand Down
6 changes: 3 additions & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@

import puma

sys.path.insert(0, os.path.abspath("../../puma"))
sys.path.insert(0, os.path.abspath("../../puma")) # noqa: PTH100


# -- Project information -----------------------------------------------------

project = "puma"
copyright = "2022, puma developers"
copyright = "2022, puma developers" # noqa: A001
author = "puma developers"

# The full version, including alpha/beta/rc tags
Expand Down Expand Up @@ -70,7 +70,7 @@
release = puma.__version__

# get git hash we are currently on (when building the docs)
current_hash = check_output(["git", "rev-parse", "HEAD"]).decode("ascii").split("\n")[0]
current_hash = check_output(["git", "rev-parse", "HEAD"]).decode("ascii").split("\n")[0] # noqa: S607
# get git hash of latest commit on main branch
commits = requests.get("https://api.github.com/repos/umami-hep/puma/commits/main")
latest_commit_hash = commits.json()["sha"]
Expand Down
11 changes: 5 additions & 6 deletions docs/sphinx_build_multiversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
This script has to be executed in the root of the repository!
"""

from __future__ import annotations

import os
Expand Down Expand Up @@ -34,7 +35,7 @@ def build_docs_version(version):

# run librep on markdown files (render placeholders with sytax §§§filename§§§)
run(
"librep --ref_dir $PWD --input 'docs/**/*.md' --no_backup",
"librep --ref_dir $PWD --input 'docs/**/*.md' --no_backup", # noqa: S607
shell=True,
check=True,
)
Expand All @@ -45,16 +46,14 @@ def build_docs_version(version):
shell=True,
check=True,
)
run("git stash", shell=True, check=True)
run("git stash", shell=True, check=True) # noqa: S607


def main():
"""main function that is executed when the script is called."""
"""Main function that is executed when the script is called."""
# get currently active branch
command = "git rev-parse --abbrev-ref HEAD".split()
initial_branch = (
run(command, capture_output=True, check=True).stdout.strip().decode("utf-8")
)
initial_branch = run(command, capture_output=True, check=True).stdout.strip().decode("utf-8")

# copy the latest conf.py, since we want to use that configuration for all the
# docs versions that are built
Expand Down
1 change: 1 addition & 0 deletions examples/high_level_aux_plots.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Produce aux task plots from tagger output and labels."""

from __future__ import annotations

from puma.hlplots import AuxResults, Tagger
Expand Down
8 changes: 5 additions & 3 deletions examples/plot_basic_histogram.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Example of histogram plot that deviates from puma default plots."""

from __future__ import annotations

import numpy as np
Expand All @@ -10,9 +11,10 @@
N_SIG = int(2e4)
rng = np.random.default_rng(seed=42)
expectation = rng.exponential(size=N_BKG)
measurement = np.concatenate(
(rng.exponential(size=N_BKG), rng.normal(loc=2, scale=0.2, size=N_SIG))
)
measurement = np.concatenate((
rng.exponential(size=N_BKG),
rng.normal(loc=2, scale=0.2, size=N_SIG),
))
expectation_hist = Histogram(expectation, label="MC", histtype="stepfilled", alpha=1)
measurement_hist = Histogram(measurement, label="dummy data")

Expand Down
3 changes: 2 additions & 1 deletion examples/plot_basic_line_plot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Example for a basic line plot with puma"""
"""Example for a basic line plot with puma."""

from __future__ import annotations

import numpy as np
Expand Down
1 change: 1 addition & 0 deletions examples/plot_data_mc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Example script that demonstrates Data/MC plots."""

from __future__ import annotations

import numpy as np
Expand Down
1 change: 1 addition & 0 deletions examples/plot_histogram_underoverflow.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Example script that demonstrates under/overflow bins."""

from __future__ import annotations

import numpy as np
Expand Down
30 changes: 6 additions & 24 deletions examples/plot_int_eff.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,35 +46,17 @@
y_scale=1.4,
)
plot.add(
IntegratedEfficiency(
rnnip["sig_disc"], rnnip["bkg_disc_b"], flavour="bjets", tagger="RRNIP"
)
IntegratedEfficiency(rnnip["sig_disc"], rnnip["bkg_disc_b"], flavour="bjets", tagger="RRNIP")
)
plot.add(
IntegratedEfficiency(
rnnip["sig_disc"], rnnip["bkg_disc_c"], flavour="cjets", tagger="RRNIP"
)
IntegratedEfficiency(rnnip["sig_disc"], rnnip["bkg_disc_c"], flavour="cjets", tagger="RRNIP")
)
plot.add(
IntegratedEfficiency(
rnnip["sig_disc"], rnnip["bkg_disc_l"], flavour="ujets", tagger="RRNIP"
)
)
plot.add(
IntegratedEfficiency(
dips["sig_disc"], dips["bkg_disc_b"], flavour="bjets", tagger="DIPS"
)
)
plot.add(
IntegratedEfficiency(
dips["sig_disc"], dips["bkg_disc_c"], flavour="cjets", tagger="DIPS"
)
)
plot.add(
IntegratedEfficiency(
dips["sig_disc"], dips["bkg_disc_l"], flavour="ujets", tagger="DIPS"
)
IntegratedEfficiency(rnnip["sig_disc"], rnnip["bkg_disc_l"], flavour="ujets", tagger="RRNIP")
)
plot.add(IntegratedEfficiency(dips["sig_disc"], dips["bkg_disc_b"], flavour="bjets", tagger="DIPS"))
plot.add(IntegratedEfficiency(dips["sig_disc"], dips["bkg_disc_c"], flavour="cjets", tagger="DIPS"))
plot.add(IntegratedEfficiency(dips["sig_disc"], dips["bkg_disc_l"], flavour="ujets", tagger="DIPS"))

plot.draw()
plot.savefig("integrated_efficiency.png", transparent=False)
1 change: 1 addition & 0 deletions examples/plot_pie.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Example plotting script for the puma.PiePlot class."""

from __future__ import annotations

from ftag import Flavours
Expand Down
1 change: 1 addition & 0 deletions examples/plot_rocs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Produce roc curves from tagger output and labels."""

from __future__ import annotations

import numpy as np
Expand Down
1 change: 1 addition & 0 deletions examples/plot_weighted_histograms.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Example script for plotting weighted histograms."""

from __future__ import annotations

import numpy as np
Expand Down
10 changes: 4 additions & 6 deletions puma/fraction_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@


def get_fx_values(resolution=100):
return np.concatenate(
(
np.logspace(-3, -1, resolution // 2),
np.linspace(0.1, 1.0, resolution // 2),
)
)
return np.concatenate((
np.logspace(-3, -1, resolution // 2),
np.linspace(0.1, 1.0, resolution // 2),
))


def get_efficiency(scores, fx):
Expand Down
Loading

0 comments on commit a0f8edf

Please sign in to comment.