Skip to content

Commit

Permalink
chore: pass mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
andrzejnovak committed Jan 31, 2025
1 parent 77043b6 commit dad5352
Showing 1 changed file with 27 additions and 28 deletions.
55 changes: 27 additions & 28 deletions src/boost_histogram/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

import copy
from builtins import sum
import numpy as np
from typing import TYPE_CHECKING, Sequence, TypeVar

import numpy as np

if TYPE_CHECKING:
from uhi.typing.plottable import PlottableAxis

Expand Down Expand Up @@ -163,31 +164,29 @@ def group_mapping(self, axis: PlottableAxis) -> Sequence[int]:
if self.factor is not None:
return [self.factor] * len(axis)
if self.edges is not None or self.axis is not None:
edges = self.edges if self.edges is not None else self.axis.edges
assert edges[0] == axis.edges[0], (
"Edges must start at first bin"
)
assert edges[-1] == axis.edges[-1], (
"Edges must end at last bin"
)
assert all(
np.isclose(
axis.edges[
np.abs(axis.edges - edge).argmin()
],
edge,
)
for edge in edges
), "Edges must be in the axis"
matched_ixes = np.where(
np.isin(
axis.edges,
edges,
)
)[0]
groups = [
int(ix - matched_ixes[i])
for i, ix in enumerate(matched_ixes[1:])
]
return groups
newedges = None
if self.axis is not None and hasattr(self.axis, "edges"):
newedges = self.axis.edges
elif self.edges is not None:
newedges = self.edges

if newedges is not None and hasattr(axis, "edges"):
assert newedges[0] == axis.edges[0], "Edges must start at first bin"
assert newedges[-1] == axis.edges[-1], "Edges must end at last bin"
assert all(
np.isclose(
axis.edges[np.abs(axis.edges - edge).argmin()],
edge,
)
for edge in newedges
), "Edges must be in the axis"
matched_ixes = np.where(
np.isin(
axis.edges,
newedges,
)
)[0]
return [
int(ix - matched_ixes[i]) for i, ix in enumerate(matched_ixes[1:])
]
raise ValueError("No rebinning factor or groups provided")

0 comments on commit dad5352

Please sign in to comment.