{"record":{"id":"df00a55251082c38","repo":"pandas-dev/pandas","slug":"resolver-of-type-name-does-not-implement-the","errorCode":null,"errorMessage":"Resolver of type '{name}' does not implement the __getitem__ method","messagePattern":"Resolver of type '(.+?)' does not implement the __getitem__ method","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"pandas/core/computation/eval.py","lineNumber":107,"sourceCode":"    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\n\n    Parameters\n    ----------\n    expr : object\n        An object that can be converted to a string\n\n    Raises\n    ------\n    ValueError\n      * If expr is an empty string","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/computation/eval.py#L89-L125","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\npd.eval('a + 1', resolvers=[my_dataclass_instance])\n\n// after\npd.eval('a + 1', resolvers=[{'a': my_series}])","handlingStrategy":"validation","validationCode":"def validate_resolvers(resolvers):\n    if resolvers is None:\n        return\n    for r in resolvers:\n        if not hasattr(r, '__getitem__'):\n            raise TypeError(f'Resolver {type(r).__name__} must support __getitem__')\n\nvalidate_resolvers(resolvers)\npd.eval(expr, resolvers=resolvers)","typeGuard":"from collections.abc import Mapping\ndef is_valid_resolver(r) -> bool:\n    return isinstance(r, Mapping) or hasattr(r, '__getitem__')","tryCatchPattern":"try:\n    pd.eval(expr, resolvers=resolvers)\nexcept TypeError as e:\n    if '__getitem__' in str(e):\n        # replace offending resolver with a dict\n        ...\n    raise","preventionTips":["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."],"tags":["pandas","eval","resolvers","type-error","duck-typing"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}