Skip to content

Commit 41f56ef

Browse files
HDembinskihenryiii
andauthored
fix: slicing projection with one-sided slices (#479)
* updated to boostorg/histogram develop with bug-fix; added test * update: boost 1.75 plus latest histogram develop * tests: update with corrected assumptions Co-authored-by: Henry Schreiner <[email protected]>
1 parent 6c9749b commit 41f56ef

File tree

7 files changed

+28
-8
lines changed

7 files changed

+28
-8
lines changed

extern/assert

extern/core

Submodule core updated 1 file

src/boost_histogram/tag.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,6 @@ def __init__(self, value):
107107
self.value = value
108108

109109
def __call__(self, axis):
110-
if self.value < -2:
111-
raise IndexError("Index cannot be less than -1")
112-
113110
return self.value
114111

115112

tests/test_histogram_indexing.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,29 @@ def test_mix_value_with_slice_2():
205205
assert_array_equal(h2.shape, (5, 2, 2))
206206

207207

208+
def test_one_sided_slice():
209+
h = bh.Histogram(bh.axis.Regular(4, 1, 5))
210+
h.view(True)[:] = 1
211+
212+
assert h[sum] == 6 # 4 (internal bins) + 2 (flow bins)
213+
assert h[bh.tag.at(-1) : bh.tag.at(5) : sum] == 6 # keeps underflow, keeps overflow
214+
215+
# check that slicing without bh.sum adds removed counts to flow bins
216+
assert_array_equal(h[1:3].view(True), [2, 1, 1, 2])
217+
218+
assert h[0::sum] == 5 # removes underflow, keeps overflow
219+
assert h[:4:sum] == 5 # removes overflow, keeps underflow
220+
assert h[0:4:sum] == 4 # removes underflow and overflow
221+
222+
assert h[bh.loc(1) :: sum] == 5 # remove underflow
223+
assert h[: bh.loc(5) : sum] == 5 # remove overflow
224+
assert h[bh.loc(1) : bh.loc(5) : sum] == 4 # removes underflow and overflow
225+
226+
assert h[bh.loc(0) :: sum] == 6 # keep underflow
227+
assert h[: bh.loc(10) + 1 : sum] == 6 # keep overflow
228+
assert h[bh.loc(0) : bh.loc(10) + 1 : sum] == 6
229+
230+
208231
def test_repr():
209232
assert repr(bh.loc(2)) == "loc(2)"
210233
assert repr(bh.loc(3) + 1) == "loc(3) + 1"

0 commit comments

Comments
 (0)