diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c531eae5..99168510 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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"] @@ -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 diff --git a/src/hist/__init__.py b/src/hist/__init__.py index bbe9a66f..457f307c 100644 --- a/src/hist/__init__.py +++ b/src/hist/__init__.py @@ -25,14 +25,15 @@ from .version import version as __version__ __all__ = ( - "__version__", - "Hist", "BaseHist", + "Hist", "NamedHist", "Stack", + "__version__", "accumulators", "axis", "loc", + "new", "numpy", "overflow", "rebin", @@ -40,7 +41,6 @@ "sum", "tag", "underflow", - "new", ) diff --git a/src/hist/_compat/typing.py b/src/hist/_compat/typing.py index 5b1bc54b..e92533ec 100644 --- a/src/hist/_compat/typing.py +++ b/src/hist/_compat/typing.py @@ -16,7 +16,7 @@ Ufunc = Any -__all__ = ["Ufunc", "ArrayLike", "Self"] +__all__ = ["ArrayLike", "Self", "Ufunc"] def __dir__() -> list[str]: diff --git a/src/hist/accumulators.py b/src/hist/accumulators.py index d3b99201..13f95e5e 100644 --- a/src/hist/accumulators.py +++ b/src/hist/accumulators.py @@ -2,4 +2,4 @@ from boost_histogram.accumulators import Mean, Sum, WeightedMean, WeightedSum -__all__ = ("Sum", "Mean", "WeightedSum", "WeightedMean") +__all__ = ("Mean", "Sum", "WeightedMean", "WeightedSum") diff --git a/src/hist/axestuple.py b/src/hist/axestuple.py index 0c5275e0..cecfe3fa 100644 --- a/src/hist/axestuple.py +++ b/src/hist/axestuple.py @@ -8,7 +8,7 @@ from ._compat.builtins import zip -__all__ = ("NamedAxesTuple", "AxesTuple", "ArrayTuple") +__all__ = ("ArrayTuple", "AxesTuple", "NamedAxesTuple") def __dir__() -> tuple[str, ...]: diff --git a/src/hist/axis/__init__.py b/src/hist/axis/__init__.py index 8d58c598..2514a24d 100644 --- a/src/hist/axis/__init__.py +++ b/src/hist/axis/__init__.py @@ -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", ) diff --git a/src/hist/axis/transform.py b/src/hist/axis/transform.py index fa911c59..a8c4ed54 100644 --- a/src/hist/axis/transform.py +++ b/src/hist/axis/transform.py @@ -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") diff --git a/src/hist/basehist.py b/src/hist/basehist.py index 3d0a99b7..1bd97689 100644 --- a/src/hist/basehist.py +++ b/src/hist/basehist.py @@ -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" @@ -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: diff --git a/src/hist/interop.py b/src/hist/interop.py index 3dbc54ce..e77422ca 100644 --- a/src/hist/interop.py +++ b/src/hist/interop.py @@ -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)) @@ -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)) diff --git a/src/hist/intervals.py b/src/hist/intervals.py index e5ec2548..49fd35ff 100644 --- a/src/hist/intervals.py +++ b/src/hist/intervals.py @@ -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, ...]: @@ -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( diff --git a/src/hist/plot.py b/src/hist/plot.py index 9690660b..4e6df3ff 100644 --- a/src/hist/plot.py +++ b/src/hist/plot.py @@ -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 diff --git a/src/hist/quick_construct.py b/src/hist/quick_construct.py index 95861caf..2bf8e2f6 100644 --- a/src/hist/quick_construct.py +++ b/src/hist/quick_construct.py @@ -19,8 +19,8 @@ class QuickConstruct: """ __slots__ = ( - "hist_class", "axes", + "hist_class", ) def __repr__(self) -> str: diff --git a/src/hist/storage.py b/src/hist/storage.py index 045e2bd2..0eedb1e8 100644 --- a/src/hist/storage.py +++ b/src/hist/storage.py @@ -12,12 +12,12 @@ ) __all__ = ( - "Storage", - "Int64", - "Double", "AtomicInt64", + "Double", + "Int64", + "Mean", + "Storage", "Unlimited", "Weight", - "Mean", "WeightedMean", ) diff --git a/src/hist/svgplots.py b/src/hist/svgplots.py index c7b9b64e..a9379d56 100644 --- a/src/hist/svgplots.py +++ b/src/hist/svgplots.py @@ -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( @@ -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) @@ -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 = [] diff --git a/src/hist/tag.py b/src/hist/tag.py index a6c6bd81..ff125d27 100644 --- a/src/hist/tag.py +++ b/src/hist/tag.py @@ -11,4 +11,4 @@ underflow, ) -__all__ = ("Slicer", "Locator", "at", "loc", "overflow", "underflow", "rebin", "sum") +__all__ = ("Locator", "Slicer", "at", "loc", "overflow", "rebin", "sum", "underflow") diff --git a/tests/test_general.py b/tests/test_general.py index bcd86229..4be9eaf2 100644 --- a/tests/test_general.py +++ b/tests/test_general.py @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/tests/test_named.py b/tests/test_named.py index 81385802..25760448 100644 --- a/tests/test_named.py +++ b/tests/test_named.py @@ -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}] @@ -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}] @@ -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}] @@ -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}]