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

Better lookup error #654

Merged
merged 2 commits into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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