Skip to content

Commit b939bc6

Browse files
committed
fix: support scaling and adding flow bins
1 parent f812a7d commit b939bc6

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

src/boost_histogram/_internal/hist.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ def _compute_inplace_op(
380380
)
381381
)
382382
else:
383-
view = self.view(flow=False)
383+
view = self.view(flow=True)
384384
getattr(view, name)(other)
385385
self._variance_known = False
386386
return self

tests/test_histogram.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1178,7 +1178,7 @@ def test_add_broadcast():
11781178

11791179
h2 = h + [[1]]
11801180
assert h2.sum() == 10 * 20
1181-
assert h2.sum(flow=True) == 10 * 20
1181+
assert h2.sum(flow=True) == 12 * 22
11821182

11831183
h3 = h + np.ones((10, 20))
11841184
assert h3.sum() == 10 * 20

tests/test_histogram_indexing.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,3 +429,29 @@ def test_single_flow_bin():
429429
assert h[3::sum] == 1
430430

431431
assert h[1:2][sum] == 5
432+
433+
434+
# issue 579
435+
436+
437+
def test_scale_flowbins():
438+
w = 1e-1
439+
x = np.random.normal(loc=0.4, scale=0.4, size=100)
440+
441+
h = bh.Histogram(bh.axis.Variable([0, 0.5, 1]), storage=bh.storage.Weight())
442+
443+
h.fill(x, weight=w)
444+
445+
ref_value = h.values(flow=True) * 5
446+
scale_value = (h * 5).values(flow=True)
447+
448+
assert scale_value == approx(ref_value)
449+
450+
451+
def test_add_flowbins():
452+
h = bh.Histogram(bh.axis.Variable([0, 0.5, 1]), storage=bh.storage.Weight())
453+
454+
ref_value = h.values(flow=True) + 5
455+
scale_value = (h + 5).values(flow=True)
456+
457+
assert scale_value == approx(ref_value)

0 commit comments

Comments
 (0)