pola-rs/polars · error · ValueError
Unexpected symbol
Error message
Unexpected symbol: {a} What it means
`_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: ...').
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
Example fix
// before
scan_iceberg(src, filter=pc.field('a') + 1 == 2) # unsupported arithmetic
// after
scan_iceberg(src, filter=pc.field('a') == 1) Defensive patterns
Strategy: validation
Validate before calling
import ast
def predicate_is_supported(expr) -> bool:
allowed = (ast.Constant, ast.Call, ast.Compare, ast.UnaryOp, ast.Attribute, ast.List, ast.BinOp)
return all(isinstance(node, allowed) for node in ast.walk(ast.parse(expr_source(expr)))) Type guard
def is_supported_predicate_node(node) -> bool:
import ast
return isinstance(node, (ast.Constant, ast.Call, ast.Compare, ast.UnaryOp, ast.Attribute, ast.List, ast.BinOp)) Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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).
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18).
Data as JSON: /api/errors/35616084c634f524.
Report an issue: GitHub.
Appendix: source
Thrown at py-polars/src/polars/io/iceberg/_utils.py:238
We need this to convert it into a PyIceberg expression.
Parameters
----------
expr
The string expression
Returns
-------
The AST representing the Arrow expression
"""
return ast.parse(expr, mode="eval").body
@singledispatch
def _convert_predicate(a: Any) -> Any:
"""Walks the AST to convert the PyArrow expression to a PyIceberg expression."""
msg = f"Unexpected symbol: {a}"
raise ValueError(msg)
@_convert_predicate.register(Constant)
def _(a: Constant) -> Any:
return a.value
@_convert_predicate.register(Name)
def _(a: Name) -> Any:
return a.id
@_convert_predicate.register(UnaryOp)
def _(a: UnaryOp) -> Any:
if isinstance(a.op, Invert):
operand = _ensure_boolean_expression(_convert_predicate(a.operand))
return pyiceberg.expressions.Not(operand)
else:View on GitHub (pinned to fe841f959e)