{"record":{"id":"4de4e78c3d0e888d","repo":"pandas-dev/pandas","slug":"invalid-engine-engine-passed-valid-engines-ar","errorCode":null,"errorMessage":"Invalid engine '{engine}' passed, valid engines are {valid_engines}","messagePattern":"Invalid engine '(.+?)' passed, valid engines are (.+?)","errorType":"exception","errorClass":"KeyError","httpStatus":null,"severity":"error","filePath":"pandas/core/computation/eval.py","lineNumber":67,"sourceCode":"    KeyError\n      * If an invalid engine is passed.\n    ImportError\n      * If numexpr was requested but doesn't exist.\n\n    Returns\n    -------\n    str\n        Engine name.\n    \"\"\"\n    from pandas.core.computation.check import NUMEXPR_INSTALLED\n    from pandas.core.computation.expressions import USE_NUMEXPR\n\n    if engine is None:\n        engine = \"numexpr\" if USE_NUMEXPR else \"python\"\n\n    if engine not in ENGINES:\n        valid_engines = list(ENGINES.keys())\n        raise KeyError(\n            f\"Invalid engine '{engine}' passed, valid engines are {valid_engines}\"\n        )\n\n    # TODO: validate this in a more general way (thinking of future engines\n    # that won't necessarily be import-able)\n    # Could potentially be done on engine instantiation\n    if engine == \"numexpr\" and not NUMEXPR_INSTALLED:\n        raise ImportError(\n            \"'numexpr' is not installed or an unsupported version. Cannot use \"\n            \"engine='numexpr' for query/eval if 'numexpr' is not installed\"\n        )\n\n    return engine\n\n\ndef _check_parser(parser: str) -> None:\n    \"\"\"\n    Make sure a valid parser is passed.","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/computation/eval.py#L49-L85","documentation":"Raised by _check_engine (pandas/core/computation/eval.py:67) as a KeyError when the `engine` argument to pd.eval / DataFrame.eval / DataFrame.query is not one of the registered engines (the keys of ENGINES, typically 'numexpr' and 'python'). Validation happens up front so no partial evaluation is attempted.","triggerScenarios":"`df.query('x > 0', engine='cython')`, `pd.eval('1+1', engine='numpy')`, a typo like `engine='numexpr2'`, or passing a non-string.","commonSituations":"Typos, guessing an engine name, stale code referencing a removed/renamed engine, or dynamic engine selection with an unvalidated config value.","solutions":["Use a valid engine: 'python' (always available) or 'numexpr' (if installed).","Omit engine to let pandas choose the default ('numexpr' if available else 'python').","Validate config-supplied engine names against `pandas.core.computation.engines.ENGINES.keys()` before passing."],"exampleFix":"# before\ndf.query('x > 0', engine='cython')\n\n# after\ndf.query('x > 0', engine='python')","handlingStrategy":"validation","validationCode":"from pandas.core.computation.engines import ENGINES\n\ndef validate_engine(engine):\n    if engine is not None and engine not in ENGINES:\n        raise KeyError(f\"Invalid engine '{engine}', valid: {list(ENGINES)}\")\n    return engine","typeGuard":"from pandas.core.computation.engines import ENGINES\n\ndef is_valid_engine(engine) -> bool:\n    return engine is None or engine in ENGINES","tryCatchPattern":"try:\n    result = df.query('x > 0', engine=engine)\nexcept KeyError as e:\n    if 'Invalid engine' in str(e):\n        result = df.query('x > 0', engine='python')\n    else:\n        raise","preventionTips":["Restrict engine choices to 'python' or 'numexpr'.","Validate config-supplied engine names against ENGINES.keys().","Omit engine to use the auto-detected default."],"tags":["eval","query","engine","validation","keyerror"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}