{"record":{"id":"3fbe914ca7d24f2e","repo":"pandas-dev/pandas","slug":"invalid-parser-parser-passed-valid-parsers-ar","errorCode":null,"errorMessage":"Invalid parser '{parser}' passed, valid parsers are {PARSERS.keys()}","messagePattern":"Invalid parser '(.+?)' passed, valid parsers are (.+?)","errorType":"exception","errorClass":"KeyError","httpStatus":null,"severity":"error","filePath":"pandas/core/computation/eval.py","lineNumber":97,"sourceCode":"\n    return engine\n\n\ndef _check_parser(parser: str) -> None:\n    \"\"\"\n    Make sure a valid parser is passed.\n\n    Parameters\n    ----------\n    parser : str\n\n    Raises\n    ------\n    KeyError\n      * If an invalid parser is passed\n    \"\"\"\n    if parser not in PARSERS:\n        raise KeyError(\n            f\"Invalid parser '{parser}' passed, valid parsers are {PARSERS.keys()}\"\n        )\n\n\ndef _check_resolvers(resolvers) -> None:\n    if resolvers is not None:\n        for resolver in resolvers:\n            if not hasattr(resolver, \"__getitem__\"):\n                name = type(resolver).__name__\n                raise TypeError(\n                    f\"Resolver of type '{name}' does not \"\n                    \"implement the __getitem__ method\"\n                )\n\n\ndef _check_expression(expr) -> None:\n    \"\"\"\n    Make sure an expression is not an empty string","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/computation/eval.py#L79-L115","documentation":"Raised by _check_parser() when the parser argument is not one of the keys in PARSERS, which are {'python', 'pandas'} (see expr.py:866). The parser controls how the expression string is converted to an AST before evaluation; an unknown parser string means pandas cannot select a visitor class. Note the error message prints the dict_keys object rather than a list, which can look unusual in logs.","triggerScenarios":"Calling pd.eval(expr, parser='numpy') or any typo such as parser='Python' (capital P) or parser='py'. Also triggered by passing a parser value loaded from config that was misspelled.","commonSituations":"Case-sensitivity mistakes ('Python' vs 'python'); copy-paste from documentation that abbreviated the option; dynamic code that builds the parser name from a variable with a typo.","solutions":["Use one of the two valid parsers: parser='pandas' (default, allows 'and'/'or'/'not' and '@' locals) or parser='python' (strict Python semantics).","If the parser name comes from config or a variable, validate it against {'pandas','python'} before the call.","Check for leading/trailing whitespace or accidental capitalization in the parser string."],"exampleFix":"// before\npd.eval('a + b', parser='Python')\n\n// after\npd.eval('a + b', parser='python')","handlingStrategy":"validation","validationCode":"VALID_PARSERS = {'pandas', 'python'}\nif parser not in VALID_PARSERS:\n    raise ValueError(f'parser must be one of {VALID_PARSERS}, got {parser!r}')\npd.eval(expr, parser=parser)","typeGuard":"def is_valid_parser(p: str) -> bool:\n    return isinstance(p, str) and p in {'pandas', 'python'}","tryCatchPattern":"try:\n    pd.eval(expr, parser=parser)\nexcept KeyError as e:\n    # invalid parser\n    raise ValueError(f'Bad parser: {parser}') from e","preventionTips":["Never construct parser strings dynamically without validation.","Centralize allowed parser values in a constant.","Use lowercase only."],"tags":["pandas","eval","parser","validation","argument-error"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}