From 602e8a25889d8a19d23b30ba6314a0dc58556181 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Fri, 23 Aug 2024 16:15:52 -0400 Subject: [PATCH] fix: the result of group_mapping() should be checked for None Signed-off-by: Henry Schreiner --- src/boost_histogram/_internal/hist.py | 8 ++++++-- src/boost_histogram/tag.py | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/boost_histogram/_internal/hist.py b/src/boost_histogram/_internal/hist.py index b9f1ef2c..9dc5b906 100644 --- a/src/boost_histogram/_internal/hist.py +++ b/src/boost_histogram/_internal/hist.py @@ -862,8 +862,12 @@ def __getitem__(self: H, index: IndexingExpr) -> H | float | Accumulator: if ind.step is not None: if getattr(ind.step, "factor", None) is not None: merge = ind.step.factor - elif getattr(ind.step, "group_mapping", None) is not None: - groups = ind.step.group_mapping(self.axes[i]) + elif ( + hasattr(ind.step, "group_mapping") + and (tmp_groups := ind.step.group_mapping(self.axes[i])) + is not None + ): + groups = tmp_groups elif callable(ind.step): if ind.step is sum: integrations.add(i) diff --git a/src/boost_histogram/tag.py b/src/boost_histogram/tag.py index 1c435495..fa4154e1 100644 --- a/src/boost_histogram/tag.py +++ b/src/boost_histogram/tag.py @@ -11,7 +11,7 @@ from ._internal.typing import AxisLike -__all__ = ("Slicer", "Locator", "at", "loc", "overflow", "underflow", "sum", "rebin") +__all__ = ("Slicer", "Locator", "at", "loc", "overflow", "underflow", "rebin", "sum") class Slicer: