Skip to content

Chooses eval engine automatically depending on whether numexpr is installed #12605

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

Closed
wants to merge 2 commits into from
Closed
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
13 changes: 11 additions & 2 deletions pandas/computation/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def _check_for_locals(expr, stack_level, parser):
raise SyntaxError(msg)


def eval(expr, parser='pandas', engine='numexpr', truediv=True,
def eval(expr, parser='pandas', engine=None, truediv=True,
local_dict=None, global_dict=None, resolvers=(), level=0,
target=None, inplace=None):
"""Evaluate a Python expression as a string using various backends.
Expand Down Expand Up @@ -160,7 +160,7 @@ def eval(expr, parser='pandas', engine='numexpr', truediv=True,
``'python'`` parser to retain strict Python semantics. See the
:ref:`enhancing performance <enhancingperf.eval>` documentation for
more details.
engine : string, default 'numexpr', {'python', 'numexpr'}
engine : string, default None, {'python', 'numexpr'}

The engine used to evaluate the expression. Supported engines are

Expand All @@ -172,6 +172,9 @@ def eval(expr, parser='pandas', engine='numexpr', truediv=True,

More backends may be available in the future.

If set to None (the default) then uses ``'numexpr'`` if available,
otherwise uses ``'python'``.

truediv : bool, optional
Whether to use true division, like in Python >= 3
local_dict : dict or None, optional
Expand Down Expand Up @@ -227,6 +230,12 @@ def eval(expr, parser='pandas', engine='numexpr', truediv=True,
raise ValueError("multi-line expressions are only valid in the "
"context of data, use DataFrame.eval")

if engine is None:
if _NUMEXPR_INSTALLED:
engine = 'numexpr'
else:
engine = 'python'

first_expr = True
for expr in exprs:
expr = _convert_expression(expr)
Expand Down