Skip to content

Commit

Permalink
chore(backport): Update pre-commit hooks (#2492)
Browse files Browse the repository at this point in the history
* Backport:
   - PR #2442
   - PR #2464
   - PR #2474
   - PR #2480
  • Loading branch information
matthewfeickert committed May 30, 2024
1 parent 0b5b9e5 commit 1b61882
Show file tree
Hide file tree
Showing 39 changed files with 92 additions and 56 deletions.
24 changes: 9 additions & 15 deletions .github/workflows/bump-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ on:
- minor
- major
release_candidate:
type: choice
description: 'Release candidate?'
options:
- false
- true
type: boolean
description: 'Release candidate'
default: false
new_version:
description: 'New version to bump to'
required: true
Expand All @@ -27,17 +25,13 @@ on:
required: true
type: string
force:
type: choice
description: 'Force override check?'
options:
- false
- true
type: boolean
description: 'Force override check'
default: false
dry_run:
type: choice
description: 'Perform a dry run to check?'
options:
- true
- false
type: boolean
description: 'Perform a dry run to check'
default: true

jobs:
bump-version:
Expand Down
8 changes: 3 additions & 5 deletions .github/workflows/publish-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ on:
workflow_dispatch:
inputs:
publish:
type: choice
description: 'Publish to TestPyPI?'
options:
- false
- true
type: boolean
description: 'Publish to TestPyPI'
default: false

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down
22 changes: 15 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ci:

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
Expand Down Expand Up @@ -35,13 +35,13 @@ repos:
- id: rst-inline-touching-normal

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.1.9"
rev: "v0.4.3"
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]

- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.12.1
rev: 24.4.2
hooks:
- id: black-jupyter
types_or: [python, pyi, jupyter]
Expand All @@ -50,10 +50,10 @@ repos:
rev: 1.16.0
hooks:
- id: blacken-docs
additional_dependencies: [black==23.12.1]
additional_dependencies: [black==24.4.2]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.8.0
rev: v1.10.0
# check the oldest and newest supported Pythons
hooks:
- &mypy
Expand All @@ -64,12 +64,20 @@ repos:
['numpy', 'types-tqdm', 'click', 'types-jsonpatch', 'types-pyyaml', 'types-jsonschema', 'importlib_metadata', 'packaging']
args: ["--python-version=3.8"]
- <<: *mypy
name: mypy with Python 3.11
args: ["--python-version=3.11"]
name: mypy with Python 3.12
args: ["--python-version=3.12"]

- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
hooks:
- id: codespell
files: ^.*\.(py|md|rst)$
args: ["-w", "-L", "hist,gaus"]

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.28.4
hooks:
- id: check-readthedocs
args: ["--verbose"]
- id: check-github-workflows
args: ["--verbose"]
8 changes: 5 additions & 3 deletions docs/examples/notebooks/ImpactPlot.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,11 @@
" model, _, b, e = fitresults()\n",
" widths = pyhf.tensorlib.concatenate(\n",
" [\n",
" model.config.param_set(k).width()\n",
" if model.config.param_set(k).constrained\n",
" else [None] * model.config.param_set(k).n_parameters\n",
" (\n",
" model.config.param_set(k).width()\n",
" if model.config.param_set(k).constrained\n",
" else [None] * model.config.param_set(k).n_parameters\n",
" )\n",
" for k, v in model.config.par_map.items()\n",
" ]\n",
" )\n",
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""The pyhf command line interface."""

from pyhf.cli.cli import pyhf as cli
from pyhf.cli.rootio import cli as rootio
from pyhf.cli.spec import cli as spec
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/cli/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""The pyhf Command Line Interface."""

import logging

import click
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/cli/complete.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'''Shell completions for pyhf.'''

import click

try:
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/cli/infer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""The inference CLI group."""

import logging

import click
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/cli/patchset.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""The pyhf spec CLI subcommand."""

import logging

import click
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/cli/rootio.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""CLI subapps to handle conversion from ROOT."""

import logging

import click
Expand Down
9 changes: 6 additions & 3 deletions src/pyhf/cli/spec.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""The pyhf spec CLI subcommand."""

import logging

import click
Expand Down Expand Up @@ -149,9 +150,11 @@ def inspect(workspace, output_file, measurement):
('(*) ' if measurement_name == default_measurement['name'] else '')
+ measurement_name,
measurement_poi,
','.join(measurement_parameters)
if measurement_parameters
else '(none)',
(
','.join(measurement_parameters)
if measurement_parameters
else '(none)'
),
)
)

Expand Down
1 change: 1 addition & 0 deletions src/pyhf/contrib/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""CLI for functionality that will get migrated out eventually."""

import logging
import click
from pathlib import Path
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/contrib/viz/brazil.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Brazil Band Plots."""

from collections import namedtuple

import matplotlib.pyplot as plt
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/infer/calculators.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Using the calculators hypothesis tests can then be performed.
"""

from pyhf.infer.mle import fixed_poi_fit
from pyhf import get_backend
from pyhf.infer import utils
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/infer/intervals/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Interval estimation"""

import pyhf.infer.intervals.upper_limits

__all__ = ["upper_limits.upper_limit"]
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/infer/intervals/upper_limits.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Interval estimation"""

import numpy as np
from scipy.optimize import toms748

Expand Down
1 change: 1 addition & 0 deletions src/pyhf/infer/mle.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Module for Maximum Likelihood Estimation."""

from pyhf import get_backend
from pyhf.exceptions import UnspecifiedPOI

Expand Down
1 change: 1 addition & 0 deletions src/pyhf/interpolators/code0.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Piecewise-linear Interpolation. (Code 0)."""

import logging
import pyhf
from pyhf.tensor.manager import get_backend
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/interpolators/code1.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Piecewise-Exponential Interpolation (Code 1)."""

import logging
import math
import pyhf
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/interpolators/code2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Quadratic Interpolation (Code 2)."""

import logging
import pyhf
from pyhf.tensor.manager import get_backend
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/interpolators/code4.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Polynomial Interpolation (Code 4)."""

import logging
import math
import pyhf
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/interpolators/code4p.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Piecewise-Linear + Polynomial Interpolation (Code 4p)."""

import logging
import pyhf
from pyhf.tensor.manager import get_backend
Expand Down
6 changes: 3 additions & 3 deletions src/pyhf/modifiers/shapesys.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ def _reindex_access_field(self, pdfconfig):

sample_mask = self._shapesys_mask[syst_index][singular_sample_index][0]
access_field_for_syst_and_batch[sample_mask] = selection
self._access_field[
syst_index, batch_index
] = access_field_for_syst_and_batch
self._access_field[syst_index, batch_index] = (
access_field_for_syst_and_batch
)

def _precompute(self):
tensorlib, _ = get_backend()
Expand Down
15 changes: 9 additions & 6 deletions src/pyhf/modifiers/staterror.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,12 @@ def finalize(self):
relerrs = default_backend.sum(
[
[
(modifier_data['data']['uncrt'][binnr] / nomsall[binnr]) ** 2
if nomsall[binnr] > 0
else 0.0
(
(modifier_data['data']['uncrt'][binnr] / nomsall[binnr])
** 2
if nomsall[binnr] > 0
else 0.0
)
for binnr in range(len(modifier_data['data']['nom_data']))
]
for modifier_data in self.builder_data[modname].values()
Expand Down Expand Up @@ -184,9 +187,9 @@ def _reindex_access_field(self, pdfconfig):

sample_mask = self._staterror_mask[syst_index][singular_sample_index][0]
access_field_for_syst_and_batch[sample_mask] = selection
self._access_field[
syst_index, batch_index
] = access_field_for_syst_and_batch
self._access_field[syst_index, batch_index] = (
access_field_for_syst_and_batch
)

def _precompute(self):
if not self.param_viewer.index_selection:
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/optimize/common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Common Backend Shim to prepare minimization for optimizer."""

from pyhf.tensor.manager import get_backend
from pyhf.tensor.common import _TensorViewer

Expand Down
1 change: 1 addition & 0 deletions src/pyhf/optimize/mixins.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Helper Classes for use of automatic differentiation."""

import logging

import numpy as np
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/optimize/opt_minuit.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Minuit Optimizer Class."""

from pyhf import exceptions
from pyhf.optimize.mixins import OptimizerMixin
import scipy
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/optimize/opt_scipy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""SciPy Optimizer Class."""

from pyhf import exceptions
from pyhf.optimize.mixins import OptimizerMixin
import scipy
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/optimize/opt_tflow.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tensorflow Backend Function Shim."""

from pyhf import get_backend
import tensorflow as tf

Expand Down
8 changes: 5 additions & 3 deletions src/pyhf/parameters/paramview.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ def extract_index_access(baseviewer, subviewer, indices):

# the transpose is here so that modifier code doesn't have to do it
indices_concatenated = tensorlib.astensor(
tensorlib.einsum('ij->ji', stitched)
if len(tensorlib.shape(stitched)) > 1
else stitched,
(
tensorlib.einsum('ij->ji', stitched)
if len(tensorlib.shape(stitched)) > 1
else stitched
),
dtype='int',
)
return index_selection, stitched, indices_concatenated
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/patchset.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
pyhf patchset provides a user-friendly interface for interacting with patchsets.
"""

import logging
import jsonpatch
from pyhf import exceptions
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/probability.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""The probability density function module."""

from pyhf import get_backend

__all__ = ["Independent", "Normal", "Poisson", "Simultaneous"]
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/schema/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
See :class:`~pyhf.schema.Schema` for documentation.
"""

import pathlib
import sys
from pyhf.schema.loader import load_schema
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/tensor/numpy_backend.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""NumPy Tensor Library Module."""

from __future__ import annotations

import logging
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/tensor/pytorch_backend.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""PyTorch Tensor Library Module."""

import torch
import torch.autograd
from torch.distributions.utils import broadcast_all
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/tensor/tensorflow_backend.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tensorflow Tensor Library Module."""

import logging
import tensorflow as tf
import tensorflow_probability as tfp
Expand Down
Loading

0 comments on commit 1b61882

Please sign in to comment.