Skip to content

Commit 3b8d5f3

Browse files
fix: label/name propogation broken passing though histograms (#630)
Fix #549. --------- Signed-off-by: Henry Schreiner <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 8c81345 commit 3b8d5f3

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/hist/basehist.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,6 @@ def __init__(
127127
"""
128128
self._hist: Any = None
129129
self.axes: NamedAxesTuple
130-
self.name = name
131-
self.label = label
132130

133131
args: tuple[AxisTypes, ...]
134132

@@ -179,6 +177,9 @@ def __init__(
179177
if data is not None:
180178
self[...] = data
181179

180+
self.name = name
181+
self.label = label
182+
182183
# Backport of storage_type from boost-histogram 1.3.2:
183184
if not hasattr(bh.Histogram, "storage_type"):
184185

tests/test_bh.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,12 @@ def test_bh_conversion():
2020
assert not isinstance(h3.axes[0], hist.axis.Regular)
2121
assert h2.axes[0].name == "y"
2222
assert h3.axes[0].metadata == {"name": "x"}
23+
24+
25+
def test_bh_conversion_add_metadata():
26+
h = bh.Histogram(bh.axis.Regular(3, 2, 1))
27+
28+
h2 = hist.Hist(h, label="abc", name="def")
29+
30+
assert h2.label == "abc"
31+
assert h2.name == "def"

0 commit comments

Comments
 (0)