diff --git a/coffea/hist/hist_tools.py b/coffea/hist/hist_tools.py index 738c43a33..1ee2ebcc0 100644 --- a/coffea/hist/hist_tools.py +++ b/coffea/hist/hist_tools.py @@ -954,6 +954,8 @@ def fill(self, **values): weight = values.pop("weight", None) if isinstance(weight, (awkward1.Array, np.ndarray)): weight = coffea.util._ensure_flat(weight) + if isinstance(weight, numbers.Number): + weight = np.atleast_1d(weight) if not all(d.name in values for d in self._axes): missing = ", ".join(d.name for d in self._axes if d.name not in values) raise ValueError("Not all axes specified for %r. Missing: %s" % (self, missing)) diff --git a/tests/test_hist_tools.py b/tests/test_hist_tools.py index 0d8d61d3f..fec8d00b0 100644 --- a/tests/test_hist_tools.py +++ b/tests/test_hist_tools.py @@ -265,3 +265,7 @@ def test_issue_333(): axis = hist.Bin("channel", "Channel b1", 50, 0, 2000) temp = np.arange(0, 2000, 40, dtype=np.int16) assert np.all(axis.index(temp) == np.arange(50) + 1) + +def test_issue_394(): + dummy = hist.Hist("Dummy" , hist.Cat("sample", "sample"), hist.Bin("dummy", "Number of events", 1, 0, 1)) + dummy.fill(sample="test", dummy=1, weight=0.5)