Skip to content

Commit dcf56d0

Browse files
authored
Fix bug with bh.sum and underflow bin off (#300)
1 parent 1cbd74a commit dcf56d0

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

boost_histogram/_internal/hist.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ class ext_sum:
550550
if self.axes[i].options.underflow:
551551
reduced._hist._reset_row(i, -1)
552552
for i in zeroes_stop:
553-
if self.axes[i].options.underflow:
553+
if self.axes[i].options.overflow:
554554
reduced._hist._reset_row(i, reduced.axes[i].size)
555555

556556
result = (

tests/test_histogram_indexing.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,23 @@ def test_noflow_slicing():
220220
assert_array_equal(h[:, :, False].view(), 0)
221221

222222

223+
def test_singleflow_slicing():
224+
h = bh.Histogram(
225+
bh.axis.Integer(0, 4, underflow=False), bh.axis.Integer(0, 4, overflow=False)
226+
)
227+
228+
vals = np.arange(4 * 4).reshape(4, 4)
229+
h[:, :] = vals
230+
231+
assert h[0, 0] == 0
232+
assert h[0, 1] == 1
233+
assert h[1, 0] == 4
234+
assert h[1, 1] == 5
235+
236+
assert_array_equal(h[:, 1 : 3 : bh.sum], vals[:, 1:3].sum(axis=1))
237+
assert_array_equal(h[1 : 3 : bh.sum, :], vals[1:3, :].sum(axis=0))
238+
239+
223240
def test_pick_str_category():
224241
noflow = dict(underflow=False, overflow=False)
225242

@@ -247,17 +264,19 @@ def test_pick_int_category():
247264
h = bh.Histogram(
248265
bh.axis.Regular(10, 0, 10),
249266
bh.axis.Regular(10, 0, 10, **noflow),
250-
bh.axis.IntCategory([3, 5, 7]),
267+
bh.axis.IntCategory([3, 5, 7, 12, 13]),
251268
)
252269

253270
vals = np.arange(100).reshape(10, 10)
254271
h[:, :, bh.loc(3)] = vals
255272
h[:, :, bh.loc(5)] = vals + 1
273+
h[:, :, 3] = vals + 100
256274

257275
assert h[0, 1, bh.loc(3)] == 1
258276
assert h[1, 0, bh.loc(5)] == 10 + 1
259277
assert h[1, 1, bh.loc(5)] == 11 + 1
260278
assert h[3, 4, bh.loc(7)] == 0
279+
assert h[3, 4, bh.loc(12)] == 134
261280

262281
assert_array_equal(h[:, :, bh.loc(3)].view(), vals)
263282
assert_array_equal(h[:, :, bh.loc(5)].view(), vals + 1)

0 commit comments

Comments
 (0)