Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pre-commit.ci] pre-commit autoupdate #954

Merged
merged 5 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .ci/release_check.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Ensure that current version is not in conflict with published releases."""

from pkg_resources import parse_version
import subprocess as subp
from pathlib import PurePath
Expand Down
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ repos:

# Python formatting
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.11.0
rev: 24.1.1
hooks:
- id: black

# Ruff linter, replacement for flake8, pydocstyle, isort
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.1.6'
rev: 'v0.1.14'
hooks:
- id: ruff
args: [--fix, --show-fixes]
Expand All @@ -62,7 +62,7 @@ repos:

# Python type checking
- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v1.7.1'
rev: 'v1.8.0'
hooks:
- id: mypy
additional_dependencies: [numpy]
Expand Down
1 change: 1 addition & 0 deletions src/iminuit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def fcn(x, y, z):
* Code: https://github.com/scikit-hep/iminuit
* Docs: https://iminuit.readthedocs.io
"""

from iminuit.minuit import Minuit
from iminuit.minimize import minimize
from iminuit.util import describe
Expand Down
39 changes: 19 additions & 20 deletions src/iminuit/cost.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
the histogram, the sum of weights and the sum of squared weights is needed then, see
class documentation for details.
"""

from __future__ import annotations

from .util import (
Expand Down Expand Up @@ -194,14 +195,14 @@ def __init__(self, val: ArrayLike, var: ArrayLike):
self._obs = val * self._scale

@overload
def __call__(self, val: ArrayLike) -> Tuple[NDArray, NDArray]:
... # pragma: no cover
def __call__(
self, val: ArrayLike
) -> Tuple[NDArray, NDArray]: ... # pragma: no cover

@overload
def __call__(
self, val: ArrayLike, var: ArrayLike
) -> Tuple[NDArray, NDArray, NDArray]:
... # pragma: no cover
) -> Tuple[NDArray, NDArray, NDArray]: ... # pragma: no cover

def __call__(self, val, var=None):
"""
Expand Down Expand Up @@ -657,16 +658,13 @@ def has_grad(self) -> bool:
return self._has_grad()

@abc.abstractmethod
def _value(self, args: Sequence[float]) -> float:
... # pragma: no cover
def _value(self, args: Sequence[float]) -> float: ... # pragma: no cover

@abc.abstractmethod
def _grad(self, args: Sequence[float]) -> NDArray:
... # pragma: no cover
def _grad(self, args: Sequence[float]) -> NDArray: ... # pragma: no cover

@abc.abstractmethod
def _has_grad(self) -> bool:
... # pragma: no cover
def _has_grad(self) -> bool: ... # pragma: no cover


class Constant(Cost):
Expand Down Expand Up @@ -920,8 +918,7 @@ def _ndata(self):
return np.prod(self._masked.shape[: self._ndim])

@abc.abstractmethod
def _pulls(self, args: Sequence[float]) -> NDArray:
... # pragma: no cover
def _pulls(self, args: Sequence[float]) -> NDArray: ... # pragma: no cover


class UnbinnedCost(MaskedCost):
Expand Down Expand Up @@ -1054,8 +1051,9 @@ def covariance(self, *args: float) -> NDArray:
return np.linalg.inv(self.fisher_information(*args))

@abc.abstractmethod
def _pointwise_score(self, args: Sequence[float]) -> NDArray:
... # pragma: no cover
def _pointwise_score(
self, args: Sequence[float]
) -> NDArray: ... # pragma: no cover

def _has_grad(self) -> bool:
return self._model_grad is not None
Expand Down Expand Up @@ -1402,8 +1400,9 @@ def _visualize(self, args: Sequence[float]) -> None:
plt.stairs(mu, xe, fill=True, color="C0")

@abc.abstractmethod
def _pred(self, args: Sequence[float]) -> Union[NDArray, Tuple[NDArray, NDArray]]:
... # pragma: no cover
def _pred(
self, args: Sequence[float]
) -> Union[NDArray, Tuple[NDArray, NDArray]]: ... # pragma: no cover

def _n_err(self) -> Tuple[NDArray, NDArray]:
d = self.data
Expand Down Expand Up @@ -1440,14 +1439,14 @@ def _update_cache(self):
self._set_bohm_zech(self._masked, self._bohm_zech_scale is not None)

@overload
def _transformed(self, val: NDArray) -> Tuple[NDArray, NDArray]:
... # pragma: no cover
def _transformed(
self, val: NDArray
) -> Tuple[NDArray, NDArray]: ... # pragma: no cover

@overload
def _transformed(
self, val: NDArray, var: NDArray
) -> Tuple[NDArray, NDArray, NDArray]:
... # pragma: no cover
) -> Tuple[NDArray, NDArray, NDArray]: ... # pragma: no cover

def _transformed(self, val, var=None):
s = self._bohm_zech_scale
Expand Down
21 changes: 14 additions & 7 deletions src/iminuit/minuit.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Minuit class."""

from __future__ import annotations

import warnings
Expand Down Expand Up @@ -1242,9 +1243,11 @@ def __call__(self, par, v):
fcn,
start,
method=method,
bounds=Bounds(lower_bound, upper_bound, keep_feasible=True)
if has_limits
else None,
bounds=(
Bounds(lower_bound, upper_bound, keep_feasible=True)
if has_limits
else None
),
jac=grad,
hess=hess,
hessp=hessp,
Expand Down Expand Up @@ -1793,10 +1796,14 @@ def _draw_profile(

if text:
plt.title(
(f"{pname} = {v:.3g}")
if vmin is None
else (
"{} = {:.3g} - {:.3g} + {:.3g}".format(pname, v, v - vmin, vmax - v)
(
(f"{pname} = {v:.3g}")
if vmin is None
else (
"{} = {:.3g} - {:.3g} + {:.3g}".format(
pname, v, v - vmin, vmax - v
)
)
),
fontsize="large",
)
Expand Down
7 changes: 3 additions & 4 deletions src/iminuit/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

You can look up the interface of data classes that iminuit uses here.
"""

from __future__ import annotations
import inspect
from collections import OrderedDict
Expand Down Expand Up @@ -1118,15 +1119,13 @@ def g(x, p): ...


@overload
def describe(callable: Callable) -> List[str]:
... # pragma: no cover
def describe(callable: Callable) -> List[str]: ... # pragma: no cover


@overload
def describe(
callable: Callable, annotations: bool
) -> Dict[str, Optional[Tuple[float, float]]]:
... # pragma: no cover
) -> Dict[str, Optional[Tuple[float, float]]]: ... # pragma: no cover


def describe(callable, *, annotations=False):
Expand Down
12 changes: 4 additions & 8 deletions tests/test_describe.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,7 @@ def foo(
d: Annotated[float, Ge(1)],
e: Annotated[float, Le(2)],
f: Annotated[float, Interval(gt=2, lt=3)],
):
...
): ...

r = describe(foo, annotations=True)
assert r == {
Expand All @@ -215,8 +214,7 @@ def foo(
}

class Foo:
def __call__(self, x: NDArray, a: Annotated[float, Gt(0), Lt(1)], b: float):
...
def __call__(self, x: NDArray, a: Annotated[float, Gt(0), Lt(1)], b: float): ...

r = describe(Foo.__call__, annotations=True)
assert r == {"self": None, "x": None, "a": (0, 1), "b": None}
Expand All @@ -235,8 +233,7 @@ def foo(
c: float,
d: Annotated[float, tp.annotated_types.Gt(1)],
e: Annotated[float, tp.annotated_types.Interval(gt=0, lt=1)],
):
...
): ...

r = describe(foo, annotations=True)
assert r == {
Expand All @@ -257,8 +254,7 @@ def foo(
a: float,
b: Annotated[float, tp.Gt(1)],
c: Annotated[float, tp.Interval(gt=0, lt=1)],
):
...
): ...

r = describe(foo, annotations=True)
assert r == {
Expand Down
Loading