Skip to content

Commit

Permalink
Fix re_evaluate not taking global_dict as argument
Browse files Browse the repository at this point in the history
When evaluate an expression, it first validate and then re_evaluate,
while re_evaluate doesn't take global_dict as an argument causing getArguments
raises KeyError
  • Loading branch information
27rabbitlt committed Nov 6, 2023
1 parent 86d265e commit c5ab962
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions numexpr/necompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -970,11 +970,12 @@ def evaluate(ex: str,
out=out, order=order, casting=casting,
_frame_depth=_frame_depth, sanitize=sanitize, **kwargs)
if e is None:
return re_evaluate(local_dict=local_dict, _frame_depth=_frame_depth)
return re_evaluate(local_dict=local_dict, global_dict=global_dict, _frame_depth=_frame_depth)
else:
raise e

def re_evaluate(local_dict: Optional[Dict] = None,
global_dict: Optional[Dict] = None,
_frame_depth: int=2) -> numpy.ndarray:
"""
Re-evaluate the previous executed array expression without any check.
Expand All @@ -998,7 +999,7 @@ def re_evaluate(local_dict: Optional[Dict] = None,
except KeyError:
raise RuntimeError("A previous evaluate() execution was not found, please call `validate` or `evaluate` once before `re_evaluate`")
argnames = _numexpr_last['argnames']
args = getArguments(argnames, local_dict, _frame_depth=_frame_depth)
args = getArguments(argnames, local_dict, global_dict, _frame_depth=_frame_depth)
kwargs = _numexpr_last['kwargs']
with evaluate_lock:
return compiled_ex(*args, **kwargs)

0 comments on commit c5ab962

Please sign in to comment.