pola-rs/polars · error · NotImplementedError
TODO: map_target =
Error message
TODO: map_target = {map_target!r} What it means
polars's UDF bytecode parser in _utils/udfs.py tries to resolve the name of the object a `map`-style function was called on (the map target). If the target object type is one the parser does not recognize, it raises NotImplementedError with the repr of the target, marking an unmapped internal case. This is an explicit 'not yet supported' marker, not a user-input validation error.
Solutions
- Simplify the UDF: pass a plain function applied to an Expr/Series so polars can identify the map target.
- Rewrite the mapping as native polars expressions (col arithmetic, when/then, replace_strict) to avoid bytecode parsing entirely.
- Check your polars version and upgrade; if it persists, file an issue at pola-rs/polars with the function and the repr from the message.
Example fix
// before
df.select(pl.col('a').map_elements(lambda x: x*2))
// after
df.with_columns((pl.col('a') * 2).alias('a')) Defensive patterns
Strategy: validation
Validate before calling
def is_supported_map_target(fn):
return callable(fn) and not isinstance(fn, type) # keep targets simple; prefer Expr/Series-facing APIs Type guard
def is_udf_safe(fn) -> bool:
import inspect
return inspect.isfunction(fn) and not inspect.iscoroutinefunction(fn) Try / catch
try:
df.select(expr.map_elements(fn))
except NotImplementedError as e:
if 'TODO: map_target' in str(e):
# fall back to plain Python or native expression
... Prevention
- Prefer native polars expressions over Python UDFs
- Keep UDFs as plain functions, not partials/wrappers
- Upgrade polars before assuming a bug is yours
When it happens
Trigger: Calling map_elements / passing a Python function to map/apply whose map_target is not an Expr or Series (e.g. some lambda/callable or wrapper object the parser cannot classify); the parser's _get_target_name hits an unknown target kind while building a native expression rewrite.
Common situations: Using an exotic callable or functools.partial-like object as a UDF, or hitting a polars version where a new map-target kind was added without parser support; reporting an upstream bug after the message asks for it.
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
- `collect_all_async` is not supported by
- `collect_all` is not supported by
- `collect_async` is not supported by
- `collect_batches` is not supported by
- `from_repr` does not support data type
AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18).
Data as JSON: /api/errors/6b1b7947ba62f814.
Report an issue: GitHub.
Appendix: source
Thrown at py-polars/src/polars/_utils/udfs.py:367
return col_expr
elif map_target == "series":
if _RE_SERIES_NAMES.match(expression):
return expression.split(".", 1)[0]
# note: handle overlapping name from global variables; fallback
# through "s", "srs", "series" and (finally) srs0 -> srsN...
search_expr = expression.replace(col_expr, "")
for name in ("s", "srs", "series"):
if not re.search(rf"\b{name}\b", search_expr):
return name
n = count()
while True:
name = f"srs{next(n)}"
if not re.search(rf"\b{name}\b", search_expr):
return name
msg = f"TODO: map_target = {map_target!r}"
raise NotImplementedError(msg)
class BytecodeParser:
"""Introspect UDF bytecode and determine if we can rewrite as native expression."""
_map_target_name: str | None = None
_can_attempt_rewrite: bool | None = None
_caller_variables: dict[str, Any] | None = None
_col_expression: tuple[str, str] | NoDefault | None = NO_DEFAULT
def __init__(self, function: Callable[[Any], Any], map_target: MapTarget) -> None:
"""
Initialize BytecodeParser instance and prepare to introspect UDFs.
Parameters
----------
function : callable
The function/lambda to disassemble and introspect.View on GitHub (pinned to fe841f959e)