scikit-hep / hist

Histogramming for analysis powered by boost-histogram
https://hist.readthedocs.io
BSD 3-Clause "New" or "Revised" License
128 stars 25 forks source link

[BUG] Error message for Mean storage different than expected #537

Closed matthewfeickert closed 1 year ago

matthewfeickert commented 1 year ago

Describe the bug

In informal chat on the IRIS-HEP Slack with @alexander-held and myself @henryiii indicated that he thought the error for incorrectly using the Mean storage should be different.

If you update boost-histogram & Hist, that error should be better. There’s a chance that’s not better yet.

Steps to reproduce

$ python -m pip install --upgrade 'hist==2.7.2' 'boost-histogram==1.4.0'
# issue_537.py
from hist import Hist

categorical_hist = Hist.new.StrCat(["a", "b"], name="meas").Mean()
categorical_hist.fill([3, 4, 5], meas="a")
$ python issue_537.py
Traceback (most recent call last):
  File "/home/feickert/Code/debug/hist-categorical-axes-fill/issue_537.py", line 4, in <module>
    categorical_hist.fill([3, 4, 5], meas="a")
  File "/home/feickert/.pyenv/versions/hist-categorical-axes-fill/lib/python3.11/site-packages/hist/basehist.py", line 240, in fill
    raise TypeError(
TypeError: All axes must be accounted for in fill, you may have used a disallowed name in the axes

For the sake of completness, the API error that @alexander-held and I were making is that we should have done

from hist import Hist

categorical_hist = Hist.new.StrCat(["a", "b"], name="meas").Mean()
sample = [3, 4, 5]
categorical_hist.fill(sample=sample, meas=["a"] * len(sample))