Skip to content

Commit

Permalink
fix: partial fix
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii committed Feb 1, 2024
1 parent 44ef172 commit 0e59f87
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 23 deletions.
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ packages =
boost_histogram._internal
boost_histogram.axis
install_requires =
uhi
numpy>=1.26.0b1;python_version>='3.12'
numpy;python_version<'3.12'
typing-extensions;python_version<'3.8'
Expand Down
4 changes: 4 additions & 0 deletions src/boost_histogram/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
from . import accumulators, axis, numpy, storage
from ._internal.enum import Kind
from ._internal.hist import Histogram, IndexingExpr
from .tag import (
Rebinner as rebin,
)
from .tag import ( # pylint: disable=redefined-builtin
loc,
overflow,
Expand Down Expand Up @@ -34,6 +37,7 @@
"accumulators",
"numpy",
"loc",
"rebin",
"sum",
"underflow",
"overflow",
Expand Down
9 changes: 4 additions & 5 deletions src/boost_histogram/_internal/hist.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,12 +854,12 @@ def __getitem__(self: H, index: IndexingExpr) -> H | float | Accumulator:
if ind != slice(None):
merge = 1
if ind.step is not None:
if ind.step.factor is not None:
if getattr(ind.step, "factor", None) is not None:
merge = ind.step.factor
elif callable(ind.step):
if ind.step is sum:
integrations.add(i)
elif ind.step.groups is not None:
elif getattr(ind.step, "groups", None) is not None:
groups = ind.step.groups
else:
raise NotImplementedError
Expand Down Expand Up @@ -904,9 +904,8 @@ def __getitem__(self: H, index: IndexingExpr) -> H | float | Accumulator:
new_axes_indices += [axes[i].edges[j + 1 : j + group + 1][-1]]

Check warning on line 904 in src/boost_histogram/_internal/hist.py

View workflow job for this annotation

GitHub Actions / PyLint

Using possibly undefined loop variable 'i'
j = group

variable_axis = Variable(new_axes_indices)
variable_axis.metadata = axes[i].metadata
axes[i] = variable_axis
variable_axis = Variable(new_axes_indices, metadata=axes[i].metadata)

Check warning on line 907 in src/boost_histogram/_internal/hist.py

View workflow job for this annotation

GitHub Actions / PyLint

Using possibly undefined loop variable 'i'
axes[i] = variable_axis._axis

Check warning on line 908 in src/boost_histogram/_internal/hist.py

View workflow job for this annotation

GitHub Actions / PyLint

Using possibly undefined loop variable 'i'
reduced_view = np.take(reduced_view, range(len(reduced_view)), axis=i)

Check warning on line 909 in src/boost_histogram/_internal/hist.py

View workflow job for this annotation

GitHub Actions / PyLint

Using possibly undefined loop variable 'i'

logger.debug("Axes: %s", axes)
Expand Down
28 changes: 11 additions & 17 deletions src/boost_histogram/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

import copy
from builtins import sum
from typing import Sequence, TypeVar
from typing import TYPE_CHECKING, Sequence, TypeVar

from uhi.typing.plottable import PlottableAxis
if TYPE_CHECKING:
from uhi.typing.plottable import PlottableAxis

from ._internal.typing import AxisLike
from .axis import Regular, Variable

__all__ = ("Slicer", "Locator", "at", "loc", "overflow", "underflow", "Rebinner", "sum")

Expand Down Expand Up @@ -114,21 +114,17 @@ class Rebinner:
__slots__ = (
"factor",
"groups",
"category_map",
)

def __init__(
self,
factor: int | None = None,
*,
value: int | None = None,
groups: Sequence[int] | None = None,
) -> None:
if (
sum(i is None for i in [value, groups]) == 2
or sum(i is not None for i in [value, groups]) > 1
):
if not sum(i is None for i in [factor, groups]) == 1:
raise ValueError("exactly one, a value or groups should be provided")
self.factor = value
self.factor = factor
self.groups = groups

def __repr__(self) -> str:
Expand All @@ -144,12 +140,10 @@ def __repr__(self) -> str:
return return_str

def __call__(self, axis: PlottableAxis) -> int | Sequence[int]:
if isinstance(axis, Regular):
if self.factor is None:
raise ValueError("must provide a value")
return self.factor
if isinstance(axis, Variable):
if self.groups is None:
raise ValueError("must provide bin groups")
if self.factor is not None:
return [self.factor] * (len(axis) // self.factor)

if self.groups is not None:
return self.groups

raise NotImplementedError(axis)

0 comments on commit 0e59f87

Please sign in to comment.