pandas-dev/pandas · error · TypeError
Resolver of type ' ' does not implement the __getitem__…
Error message
Resolver of type '{name}' does not implement the __getitem__ method What it means
Raised by _check_resolvers() when an element of the resolvers list/tuple does not implement __getitem__. Resolvers are dict-like objects injected for variable name lookup (e.g., DataFrame.index and DataFrame.columns in df.query). Each resolver must support square-bracket access so the scope can resolve names like 'index' or column names to values.
Solutions
- Ensure every element of resolvers is a mapping or supports __getitem__ — wrap custom objects in a dict or add a __getitem__ method.
- Pass resolvers as a list/tuple of dicts: resolvers=[{'col': values}, {'index': idx}].
- If you only need DataFrame column/index resolution, rely on df.query/df.eval defaults and do not pass resolvers at all.
Example fix
// before
pd.eval('a + 1', resolvers=[my_dataclass_instance])
// after
pd.eval('a + 1', resolvers=[{'a': my_series}]) Defensive patterns
Strategy: validation
Validate before calling
def validate_resolvers(resolvers):
if resolvers is None:
return
for r in resolvers:
if not hasattr(r, '__getitem__'):
raise TypeError(f'Resolver {type(r).__name__} must support __getitem__')
validate_resolvers(resolvers)
pd.eval(expr, resolvers=resolvers) Type guard
from collections.abc import Mapping
def is_valid_resolver(r) -> bool:
return isinstance(r, Mapping) or hasattr(r, '__getitem__') Try / catch
try:
pd.eval(expr, resolvers=resolvers)
except TypeError as e:
if '__getitem__' in str(e):
# replace offending resolver with a dict
...
raise Prevention
- Pass only dict-like objects as resolver elements.
- Wrap custom resolver objects in a dict adapter.
- Prefer relying on df.query/df.eval defaults over custom resolvers.
When it happens
Trigger: Passing resolvers=[some_object] where some_object is a plain int, a custom class without __getitem__, a frozenset, or any non-mapping type. Common when users pass a single dict without wrapping it in a list — though a bare dict does have __getitem__, the error appears with non-dict objects like a Series.index passed directly as a resolver element rather than wrapped.
Common situations: Building a custom resolver pipeline for query(); passing a named tuple or dataclass instance expecting it to behave like a mapping; migrating code that previously passed a list of dicts and accidentally included a non-dict element.
Related errors
- Cannot assign expression output to target
- expr must be a string to be evaluated
- Only named functions are supported
- unsupported operand type(s) for
- can only assign a single expression
AI-assisted analysis of pandas-dev/pandas@3b7651241d (2026-08-11).
Data as JSON: /api/errors/df00a55251082c38.
Report an issue: GitHub.
Appendix: source
Thrown at pandas/core/computation/eval.py:107
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 string
Parameters
----------
expr : object
An object that can be converted to a string
Raises
------
ValueError
* If expr is an empty stringView on GitHub (pinned to 3b7651241d)