Skip to content

Commit

Permalink
Merge pull request #654 from CoffeaTeam/emptylookup
Browse files Browse the repository at this point in the history
Better lookup error
  • Loading branch information
lgray authored Mar 29, 2022
2 parents a3ba69e + 29f44cd commit 57f6130
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions coffea/lookup_tools/dense_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ def __init__(self, values, dims, feval_dim=None):
self._values = deepcopy(values)

def _evaluate(self, *args):
if len(args) != self._dimension:
raise ValueError(f"Insufficient arguments for correction {self}")
indices = []
if self._dimension == 1:
axes = (
Expand Down
5 changes: 5 additions & 0 deletions tests/test_lookup_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
from coffea import lookup_tools
import awkward as ak
import pytest
from coffea.util import numpy as np
from coffea.nanoevents import NanoEventsFactory

Expand Down Expand Up @@ -458,6 +459,10 @@ def test_dense_lookup():
numpy.ones(shape=(3, 4)), (numpy.linspace(0, 1, 4), numpy.linspace(0, 1, 5))
)

with pytest.raises(ValueError):
lookup(ak.Array([]))

assert ak.to_list(lookup(ak.Array([]), ak.Array([]))) == []
assert lookup(0.1, 0.3) == 1.0
assert numpy.all(lookup(0.1, numpy.array([0.3, 0.5])) == numpy.array([1.0, 1.0]))
assert ak.to_list(lookup(a, a)) == [[1.0, 1.0], [1.0]]
Expand Down

0 comments on commit 57f6130

Please sign in to comment.