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

[BUG] Indexing with negative numbers #559

Open
andrzejnovak opened this issue Feb 6, 2024 · 1 comment
Open

[BUG] Indexing with negative numbers #559

andrzejnovak opened this issue Feb 6, 2024 · 1 comment

Comments

@andrzejnovak
Copy link
Member

Describe the bug

hist doesn't process negative indexing on axes.

Steps to reproduce

import hist
import numpy as np

h1 = hist.new.Reg(10, 0, 10).Weight().fill(np.random.normal(5, 2, int(1e6)))
# Works fine
h1[1:4]

# Throws an error
h1[1:-2]

Trace:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[8], line 1
----> 1 h1[1:-2]

File ~/software/micromamba/envs/def/lib/python3.11/site-packages/hist/basehist.py:324, in BaseHist.__getitem__(self, index)
    317 def __getitem__(  # type: ignore[override]
    318     self: T, index: IndexingExpr
    319 ) -> T | float | bh.accumulators.Accumulator:
    320     """
    321     Get histogram item.
    322     """
--> 324     return super().__getitem__(self._index_transform(index))

File ~/software/micromamba/envs/def/lib/python3.11/site-packages/boost_histogram/_internal/hist.py:908, in Histogram.__getitem__(self, index)
    906         assert isinstance(start, int)
    907         assert isinstance(stop, int)
--> 908         slices.append(_core.algorithm.slice_and_rebin(i, start, stop, merge))
    910 # Will be updated below
    911 if slices or pick_set or pick_each or integrations:

ValueError: begin < end required
@matthewfeickert
Copy link
Member

@henryiii is this an intentional design choice, or is this an edge case that hadn't gotten caught yet?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants