Skip to content

Commit

Permalink
Merge pull request #399 from lgray/fix_394_backport
Browse files Browse the repository at this point in the history
Backport of #398
  • Loading branch information
lgray authored Dec 24, 2020
2 parents c1d28d2 + 1223968 commit 68ad0cc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions coffea/hist/hist_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 4 additions & 0 deletions tests/test_hist_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 68ad0cc

Please sign in to comment.