Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: slicing projection with one-sided slices #479

Merged
merged 3 commits into from
Dec 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion extern/assert
2 changes: 1 addition & 1 deletion extern/core
Submodule core updated 1 files
+4 −4 .travis.yml
3 changes: 0 additions & 3 deletions src/boost_histogram/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,6 @@ def __init__(self, value):
self.value = value

def __call__(self, axis):
if self.value < -2:
raise IndexError("Index cannot be less than -1")

return self.value


Expand Down
23 changes: 23 additions & 0 deletions tests/test_histogram_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,29 @@ def test_mix_value_with_slice_2():
assert_array_equal(h2.shape, (5, 2, 2))


def test_one_sided_slice():
h = bh.Histogram(bh.axis.Regular(4, 1, 5))
h.view(True)[:] = 1

assert h[sum] == 6 # 4 (internal bins) + 2 (flow bins)
assert h[bh.tag.at(-1) : bh.tag.at(5) : sum] == 6 # keeps underflow, keeps overflow
HDembinski marked this conversation as resolved.
Show resolved Hide resolved

# check that slicing without bh.sum adds removed counts to flow bins
assert_array_equal(h[1:3].view(True), [2, 1, 1, 2])

assert h[0::sum] == 5 # removes underflow, keeps overflow
assert h[:4:sum] == 5 # removes overflow, keeps underflow
assert h[0:4:sum] == 4 # removes underflow and overflow

assert h[bh.loc(1) :: sum] == 5 # remove underflow
assert h[: bh.loc(5) : sum] == 5 # remove overflow
assert h[bh.loc(1) : bh.loc(5) : sum] == 4 # removes underflow and overflow

assert h[bh.loc(0) :: sum] == 6 # keep underflow
assert h[: bh.loc(10) + 1 : sum] == 6 # keep overflow
HDembinski marked this conversation as resolved.
Show resolved Hide resolved
assert h[bh.loc(0) : bh.loc(10) + 1 : sum] == 6


def test_repr():
assert repr(bh.loc(2)) == "loc(2)"
assert repr(bh.loc(3) + 1) == "loc(3) + 1"
Expand Down