{"record":{"id":"35616084c634f524","repo":"pola-rs/polars","slug":"unexpected-symbol-a","errorCode":null,"errorMessage":"Unexpected symbol: {a}","messagePattern":"Unexpected symbol: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/io/iceberg/_utils.py","lineNumber":238,"sourceCode":"    We need this to convert it into a PyIceberg expression.\n\n    Parameters\n    ----------\n    expr\n        The string expression\n\n    Returns\n    -------\n    The AST representing the Arrow expression\n    \"\"\"\n    return ast.parse(expr, mode=\"eval\").body\n\n\n@singledispatch\ndef _convert_predicate(a: Any) -> Any:\n    \"\"\"Walks the AST to convert the PyArrow expression to a PyIceberg expression.\"\"\"\n    msg = f\"Unexpected symbol: {a}\"\n    raise ValueError(msg)\n\n\n@_convert_predicate.register(Constant)\ndef _(a: Constant) -> Any:\n    return a.value\n\n\n@_convert_predicate.register(Name)\ndef _(a: Name) -> Any:\n    return a.id\n\n\n@_convert_predicate.register(UnaryOp)\ndef _(a: UnaryOp) -> Any:\n    if isinstance(a.op, Invert):\n        operand = _ensure_boolean_expression(_convert_predicate(a.operand))\n        return pyiceberg.expressions.Not(operand)\n    else:","sourceCodeStart":220,"sourceCodeEnd":256,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/io/iceberg/_utils.py#L220-L256","documentation":"`_convert_predicate` is a singledispatch walker that converts a PyArrow-filter AST (parsed into Python AST nodes) into a pyiceberg expression. The base registered implementation handles no node type, so reaching it means the walker encountered an AST node kind it does not know how to translate, and it raises ValueError('Unexpected symbol: ...').","triggerScenarios":"Passing a pyarrow.compute filter expression to scan_iceberg (via try_convert_pyarrow_predicate) whose parsed AST contains an unsupported construct — e.g. lambdas, comprehensions, subscripts, or any node type without a registered dispatch handler.","commonSituations":"Using exotic pyarrow expression shapes (nested method chains, arithmetic, custom operators) in the predicate; library version drift where polars' dispatcher supports only a fixed set of AST nodes (Constant, Call, Compare, UnaryOp, Attribute, List, BinOp).","solutions":["Simplify the predicate to supported forms: field comparisons, is_null/is_nan calls, and & / | combinations","Split complex predicates into multiple simpler pyarrow expressions","Rewrite the filter as a polars/predicate string or a pyiceberg expression directly","Update polars/pyarrow versions — newer polars may support more node types"],"exampleFix":"// before\nscan_iceberg(src, filter=pc.field('a') + 1 == 2)  # unsupported arithmetic\n// after\nscan_iceberg(src, filter=pc.field('a') == 1)","handlingStrategy":"validation","validationCode":"import ast\ndef predicate_is_supported(expr) -> bool:\n    allowed = (ast.Constant, ast.Call, ast.Compare, ast.UnaryOp, ast.Attribute, ast.List, ast.BinOp)\n    return all(isinstance(node, allowed) for node in ast.walk(ast.parse(expr_source(expr))))","typeGuard":"def is_supported_predicate_node(node) -> bool:\n    import ast\n    return isinstance(node, (ast.Constant, ast.Call, ast.Compare, ast.UnaryOp, ast.Attribute, ast.List, ast.BinOp))","tryCatchPattern":null,"preventionTips":["Keep Iceberg filters to simple field comparisons and &/| combinations","Avoid arithmetic, subscripts, and compute kernels inside scan_iceberg filters","Prefer polars lazy `.filter()` for conditions Iceberg predicates can't express","Pin pyarrow versions tested against your polars release"],"tags":["iceberg","predicate","pyarrow","expression-conversion"],"backgroundTag":"unsupported-operation","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}