pandas-dev/pandas · error · KeyError
Invalid parser '{parser}' passed, valid parsers are {PARSERS
Error message
Invalid parser '{parser}' passed, valid parsers are {PARSERS.keys()} What it means
Raised by _check_parser (pandas/core/computation/eval.py:97) as a KeyError when the `parser` argument to pd.eval / DataFrame.eval is not one of the keys in PARSERS (typically 'pandas' and 'python'). The parser determines how the expression string is tokenized (e.g. whether @-prefix locals or special syntax is allowed), so an unknown parser is rejected before parsing.
Source
Thrown at pandas/core/computation/eval.py:97
return engine
def _check_parser(parser: str) -> None:
"""
Make sure a valid parser is passed.
Parameters
----------
parser : str
Raises
------
KeyError
* If an invalid parser is passed
"""
if parser not in PARSERS:
raise KeyError(
f"Invalid parser '{parser}' passed, valid parsers are {PARSERS.keys()}"
)
def _check_resolvers(resolvers) -> None:
if resolvers is not None:
for resolver in resolvers:
if not hasattr(resolver, "__getitem__"):
name = type(resolver).__name__
raise TypeError(
f"Resolver of type '{name}' does not "
"implement the __getitem__ method"
)
def _check_expression(expr) -> None:
"""
Make sure an expression is not an empty stringView on GitHub (pinned to 71959b8cb9)
Solutions
- Use a valid parser: 'pandas' or 'python'.
- Omit parser to use the default ('pandas' for DataFrame.eval).
- If you need @-local variable access, use parser='pandas' (the '@' prefix is only supported by the pandas parser).
Example fix
# before
pd.eval('a + b', parser='pyparsing')
# after
pd.eval('a + b', parser='pandas') Defensive patterns
Strategy: validation
Validate before calling
from pandas.core.computation.expr import PARSERS
def validate_parser(parser):
if parser not in PARSERS:
raise KeyError(f"Invalid parser '{parser}', valid: {list(PARSERS)}")
return parser Type guard
from pandas.core.computation.expr import PARSERS
def is_valid_parser(parser) -> bool:
return parser in PARSERS Try / catch
try:
result = pd.eval('a + b', parser=parser)
except KeyError as e:
if 'Invalid parser' in str(e):
result = pd.eval('a + b', parser='pandas')
else:
raise Prevention
- Use 'pandas' or 'python' parser only.
- Use parser='pandas' when you need @-prefixed local variables.
- Omit parser to accept the default.
When it happens
Trigger: `pd.eval('a + b', parser='pyparsing')`, `df.eval('a + b', parser='custom')`, a typo, or passing a parser name from a different pandas version.
Common situations: Typos, guessing parser names, code migrated across versions where parser naming changed, or dynamic config feeding an unvalidated value.
Related errors
- Invalid engine '{engine}' passed, valid engines are {valid_e
- Label(s) {list(cols)} do not exist
- expr cannot be an empty string
- The '@' prefix is only supported by the pandas parser
- only a single expression is allowed
AI-assisted analysis of pandas-dev/pandas@71959b8cb9 (2026-08-07).
Data as JSON: /api/errors/3fbe914ca7d24f2e.
Report an issue: GitHub.