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

chore: update pre-commit hooks #593

Merged
merged 3 commits into from
Jan 30, 2025
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
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.2
rev: v0.8.6
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
Expand All @@ -34,12 +34,12 @@ repos:
types_or: [python, pyi, jupyter]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.13.0
rev: v1.14.1
hooks:
- id: mypy
files: ^src
args: []
additional_dependencies: ["numpy~=1.26.0", "matplotlib>=3.4", "boost-histogram~=1.4.0", "uhi~=0.3.1", "pandas-stubs>=2.0.1.230501"]
additional_dependencies: ["numpy~=2.2.0", "matplotlib>=3.4", "boost-histogram~=1.5.0", "uhi~=0.3.1", "pandas-stubs>=2.0.1.230501"]

- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
Expand Down
6 changes: 3 additions & 3 deletions src/hist/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@
from .version import version as __version__

__all__ = (
"__version__",
"Hist",
"BaseHist",
"Hist",
"NamedHist",
"Stack",
"__version__",
"accumulators",
"axis",
"loc",
"new",
"numpy",
"overflow",
"rebin",
"storage",
"sum",
"tag",
"underflow",
"new",
)


Expand Down
2 changes: 1 addition & 1 deletion src/hist/_compat/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
Ufunc = Any


__all__ = ["Ufunc", "ArrayLike", "Self"]
__all__ = ["ArrayLike", "Self", "Ufunc"]


def __dir__() -> list[str]:
Expand Down
2 changes: 1 addition & 1 deletion src/hist/accumulators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

from boost_histogram.accumulators import Mean, Sum, WeightedMean, WeightedSum

__all__ = ("Sum", "Mean", "WeightedSum", "WeightedMean")
__all__ = ("Mean", "Sum", "WeightedMean", "WeightedSum")
2 changes: 1 addition & 1 deletion src/hist/axestuple.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from ._compat.builtins import zip

__all__ = ("NamedAxesTuple", "AxesTuple", "ArrayTuple")
__all__ = ("ArrayTuple", "AxesTuple", "NamedAxesTuple")


def __dir__() -> tuple[str, ...]:
Expand Down
14 changes: 7 additions & 7 deletions src/hist/axis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
from . import transform

__all__ = (
"AxisProtocol",
"ArrayTuple",
"AxesMixin",
"Regular",
"Variable",
"Integer",
"AxisProtocol",
"Boolean",
"IntCategory",
"Integer",
"NamedAxesTuple",
"Regular",
"StrCategory",
"Boolean",
"Variable",
"transform",
"NamedAxesTuple",
"ArrayTuple",
)


Expand Down
2 changes: 1 addition & 1 deletion src/hist/axis/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

from boost_histogram.axis.transform import AxisTransform, Function, Pow, log, sqrt

__all__ = ("AxisTransform", "Pow", "Function", "sqrt", "log")
__all__ = ("AxisTransform", "Function", "Pow", "log", "sqrt")
8 changes: 4 additions & 4 deletions src/hist/basehist.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,11 @@ def from_columns(
for ax in axes:
if isinstance(ax, str):
assert ax in data, f"{ax} must be present in data={list(data)}"
cats = set(data[ax]) # type: ignore[arg-type]
cats = set(data[ax])
if all(isinstance(a, str) for a in cats):
axes_list.append(hist.axis.StrCategory(sorted(cats), name=ax)) # type: ignore[arg-type]
axes_list.append(hist.axis.StrCategory(sorted(cats), name=ax))
elif all(isinstance(a, int) for a in cats):
axes_list.append(hist.axis.IntCategory(sorted(cats), name=ax)) # type: ignore[arg-type]
axes_list.append(hist.axis.IntCategory(sorted(cats), name=ax))
else:
raise TypeError(
f"{ax} must be all int or strings if axis not given"
Expand All @@ -214,7 +214,7 @@ def from_columns(

self = cls(*axes_list, storage=storage)
data_list = {x.name: data[x.name] for x in axes_list}
self.fill(**data_list, weight=weight_arr) # type: ignore[arg-type]
self.fill(**data_list, weight=weight_arr)
return self

def project(self, *args: int | str) -> Self | float | bh.accumulators.Accumulator:
Expand Down
4 changes: 2 additions & 2 deletions src/hist/interop.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def broadcast_and_flatten(
try:
arrays.append(np.asarray(arg))
except (TypeError, ValueError):
return NotImplemented
return NotImplemented # type: ignore[no-any-return]

return tuple(np.ravel(x) for x in np.broadcast_arrays(*arrays))

Expand All @@ -126,6 +126,6 @@ def broadcast_and_flatten(
try:
arrays.append(np.asarray(arg))
except (TypeError, ValueError):
return NotImplemented
return NotImplemented # type: ignore[no-any-return]

return tuple(np.ravel(x) for x in np.broadcast_arrays(*arrays))
4 changes: 2 additions & 2 deletions src/hist/intervals.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
)
raise

__all__ = ("poisson_interval", "clopper_pearson_interval", "ratio_uncertainty")
__all__ = ("clopper_pearson_interval", "poisson_interval", "ratio_uncertainty")


def __dir__() -> tuple[str, ...]:
Expand Down Expand Up @@ -107,7 +107,7 @@ def clopper_pearson_interval(
interval = np.stack((interval_min, interval_max))
interval[0, num == 0.0] = 0.0
interval[1, num == denom] = 1.0
return interval # type: ignore[no-any-return]
return interval


def ratio_uncertainty(
Expand Down
2 changes: 1 addition & 1 deletion src/hist/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def plot_ratio_array(
valid_ratios + ratio_uncert[1][valid_ratios_idx],
]
)
max_delta = np.amax(np.abs(extrema - central_value))
max_delta: float = np.amax(np.abs(extrema - central_value))
ratio_extrema = np.abs(max_delta + central_value)

_alpha = 2.0
Expand Down
2 changes: 1 addition & 1 deletion src/hist/quick_construct.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class QuickConstruct:
"""

__slots__ = (
"hist_class",
"axes",
"hist_class",
)

def __repr__(self) -> str:
Expand Down
8 changes: 4 additions & 4 deletions src/hist/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
)

__all__ = (
"Storage",
"Int64",
"Double",
"AtomicInt64",
"Double",
"Int64",
"Mean",
"Storage",
"Unlimited",
"Weight",
"Mean",
"WeightedMean",
)
6 changes: 3 additions & 3 deletions src/hist/svgplots.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def svg_hist_1d(h: hist.BaseHist) -> svg:
(edges,) = h.axes.edges
norm_edges = (edges - edges[0]) / (edges[-1] - edges[0])
density = h.density()
max_dens = np.amax(density) or 1
max_dens: float = np.amax(density) or 1 # type: ignore[redundant-expr, unreachable]
norm_vals: np.typing.NDArray[Any] = density / max_dens

arr: np.typing.NDArray[np.float64] = np.empty(
Expand Down Expand Up @@ -121,7 +121,7 @@ def svg_hist_1d_c(h: hist.BaseHist) -> svg:
(edges,) = h.axes.edges
norm_edges = (edges - edges[0]) / (edges[-1] - edges[0]) * np.pi * 2
density = h.density()
max_dens = np.amax(density) or 1
max_dens = np.amax(density) or 1 # type: ignore[redundant-expr, var-annotated, unreachable]
norm_vals: np.typing.NDArray[Any] = density / max_dens

arr: np.typing.NDArray[np.float64] = np.empty((2, len(norm_vals) * 2), dtype=float)
Expand Down Expand Up @@ -155,7 +155,7 @@ def svg_hist_2d(h: hist.BaseHist) -> svg:
ey = -(e1 - e1[0]) / (e1[-1] - e1[0]) * height

density = h.density()
max_dens = np.amax(density) or 1
max_dens = np.amax(density) or 1 # type: ignore[redundant-expr, var-annotated, unreachable]
norm_vals: np.typing.NDArray[Any] = density / max_dens

boxes = []
Expand Down
2 changes: 1 addition & 1 deletion src/hist/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
underflow,
)

__all__ = ("Slicer", "Locator", "at", "loc", "overflow", "underflow", "rebin", "sum")
__all__ = ("Locator", "Slicer", "at", "loc", "overflow", "rebin", "sum", "underflow")
8 changes: 4 additions & 4 deletions tests/test_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def test_general_fill_regular():
z_one_only = h[{2: bh.loc(1)}]
for idx_x in range(10):
for idx_y in range(10):
if idx_x == 3 and idx_y == 4 or idx_x == 4 and idx_y == 4:
if (idx_x == 3 and idx_y == 4) or (idx_x == 4 and idx_y == 4):
assert z_one_only[idx_x, idx_y] == 1
elif idx_x == 5 and idx_y == 4:
assert z_one_only[idx_x, idx_y] == 3
Expand Down Expand Up @@ -173,7 +173,7 @@ def test_general_fill_variable():
z_one_only = h[{2: bh.loc(1)}]
for idx_x in range(10):
for idx_y in range(10):
if idx_x == 3 and idx_y == 4 or idx_x == 4 and idx_y == 4:
if (idx_x == 3 and idx_y == 4) or (idx_x == 4 and idx_y == 4):
assert z_one_only[idx_x, idx_y] == 1
elif idx_x == 5 and idx_y == 4:
assert z_one_only[idx_x, idx_y] == 3
Expand All @@ -195,7 +195,7 @@ def test_general_fill_integer():
z_one_only = h[{2: bh.loc(1)}]
for idx_x in range(10):
for idx_y in range(10):
if idx_x == 3 and idx_y == 4 or idx_x == 4 and idx_y == 4:
if (idx_x == 3 and idx_y == 4) or (idx_x == 4 and idx_y == 4):
assert z_one_only[idx_x, idx_y] == 1
elif idx_x == 5 and idx_y == 4:
assert z_one_only[idx_x, idx_y] == 3
Expand Down Expand Up @@ -225,7 +225,7 @@ def test_general_fill_int_cat():
z_one_only = h[{2: bh.loc(1)}]
for idx_x in range(10):
for idx_y in range(10):
if idx_x == 3 and idx_y == 4 or idx_x == 4 and idx_y == 4:
if (idx_x == 3 and idx_y == 4) or (idx_x == 4 and idx_y == 4):
assert z_one_only[idx_x, idx_y] == 1
elif idx_x == 5 and idx_y == 4:
assert z_one_only[idx_x, idx_y] == 3
Expand Down
8 changes: 4 additions & 4 deletions tests/test_named.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def test_named_fill():
z_one_only = h[{"z": bh.loc(1)}]
for idx_x in range(10):
for idx_y in range(10):
if idx_x == 3 and idx_y == 4 or idx_x == 4 and idx_y == 4:
if (idx_x == 3 and idx_y == 4) or (idx_x == 4 and idx_y == 4):
assert (
z_one_only[idx_x, idx_y]
== z_one_only[{"x": idx_x, "y": idx_y}]
Expand Down Expand Up @@ -193,7 +193,7 @@ def test_named_fill():
z_one_only = h[{"z": bh.loc(1)}]
for idx_x in range(10):
for idx_y in range(10):
if idx_x == 3 and idx_y == 4 or idx_x == 4 and idx_y == 4:
if (idx_x == 3 and idx_y == 4) or (idx_x == 4 and idx_y == 4):
assert (
z_one_only[idx_x, idx_y]
== z_one_only[{"x": idx_x, "y": idx_y}]
Expand Down Expand Up @@ -226,7 +226,7 @@ def test_named_fill():
z_one_only = h[{"z": bh.loc(1)}]
for idx_x in range(10):
for idx_y in range(10):
if idx_x == 3 and idx_y == 4 or idx_x == 4 and idx_y == 4:
if (idx_x == 3 and idx_y == 4) or (idx_x == 4 and idx_y == 4):
assert (
z_one_only[idx_x, idx_y]
== z_one_only[{"x": idx_x, "y": idx_y}]
Expand Down Expand Up @@ -259,7 +259,7 @@ def test_named_fill():
z_one_only = h[{"z": bh.loc(1)}]
for idx_x in range(10):
for idx_y in range(10):
if idx_x == 3 and idx_y == 4 or idx_x == 4 and idx_y == 4:
if (idx_x == 3 and idx_y == 4) or (idx_x == 4 and idx_y == 4):
assert (
z_one_only[idx_x, idx_y]
== z_one_only[{"x": idx_x, "y": idx_y}]
Expand Down
Loading