{"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/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/computation/eval.py#L49-L85","documentation":"Raised by _check_engine when the `engine` argument passed to pd.eval / DataFrame.eval / DataFrame.query is not in the ENGINES registry (currently {'python', 'numexpr'}). The check is a KeyError so callers wrapping eval see a dictionary-style lookup failure. After the registry check, requesting 'numexpr' without numexpr installed raises ImportError instead.","triggerScenarios":"pd.eval('1+1', engine='rust'); df.query('a > 0', engine='numpy'); passing engine=None is fine (defaults), but a non-existent name raises.","commonSituations":"Typos ('numexpr' misspelled); copy-pasted snippets naming a removed/future engine; version drift where an engine was renamed.","solutions":["Use one of the valid engines printed in the message (typically 'python' or 'numexpr').","Omit engine= to accept the default (numexpr if installed, else python).","For 'numexpr', ensure the package is installed: pip install numexpr."],"exampleFix":"// before\npd.eval('a + b', engine='numpy')\n// after\npd.eval('a + b', engine='python')  # or omit engine=","handlingStrategy":"validation","validationCode":"valid = {'python', 'numexpr'}\nif engine not in valid:\n    raise ValueError(f'engine={engine!r}; choose from {valid}')\nresult = pd.eval(expr, engine=engine)","typeGuard":"def is_valid_engine(name: str) -> bool:\n    return name in {'python', 'numexpr'}","tryCatchPattern":null,"preventionTips":["Omit engine= to use the safe default.","Install numexpr before relying on engine='numexpr'.","Validate user-supplied engine strings against the known set."],"tags":["key-error","eval","engine","query","api-misuse"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}