pola-rs/polars · error · AssertionError

unexpected or unrecognised op name ({opname})\n\nPlease repo

Error message

unexpected or unrecognised op name ({opname})\n\nPlease report a bug to https://github.com/pola-rs/polars/issues with the content of function you were passing to the `map` expression and the following instruction object:\n{inst!r}

What it means

Internal AssertionError from InstructionTranslator.op (py-polars/src/polars/_utils/udfs.py:668-675). When you call Expr/Series.map_elements (or map_batches), polars disassembles the function's bytecode to translate it into an equivalent native expression and emit a PolarsInefficientMapWarning. If a bytecode instruction's opname is not in polars' known opcode tables (OpNames.CONTROL_FLOW/UNARY, IS_OP, CONTAINS_OP, BINARY_SUBSCR), translation aborts with this 'please report a bug' error. It almost always means a new CPython opcode version polars has not catalogued, or an exotic code construct.

Source

Thrown at py-polars/src/polars/_utils/udfs.py:675

            return OpNames.CONTROL_FLOW[opname]
        elif inst.argrepr:
            return inst.argrepr
        elif opname == "IS_OP":
            return "is not" if inst.argval else "is"
        elif opname == "CONTAINS_OP":
            return "not in" if inst.argval else "in"
        elif opname in OpNames.UNARY:
            return OpNames.UNARY[opname]
        elif opname == "BINARY_SUBSCR":
            return "replace_strict"
        else:
            msg = (
                f"unexpected or unrecognised op name ({opname})\n\n"
                "Please report a bug to https://github.com/pola-rs/polars/issues "
                "with the content of function you were passing to the `map` "
                f"expression and the following instruction object:\n{inst!r}"
            )
            raise AssertionError(msg)

    def _expr(self, value: StackEntry, col: str, param_name: str, depth: int) -> str:
        """Take stack entry value and convert to polars expression string."""
        if isinstance(value, StackValue):
            op = _RE_STRIP_BOOL.sub(r"\1", value.operator)
            e1 = self._expr(value.left_operand, col, param_name, depth + 1)
            if value.operator_arity == 1:
                if op not in OpNames.UNARY_VALUES:
                    if e1.startswith("pl.col("):
                        call = "" if op.endswith(")") else "()"
                        return f"{e1}.{op}{call}"
                    if e1[0] in OpNames.UNARY_VALUES and e1[1:].startswith("pl.col("):
                        call = "" if op.endswith(")") else "()"
                        return f"({e1}).{op}{call}"

                    # support use of consts as numpy/builtin params, eg:
                    # "np.sin(3) + np.cos(x)", or "len('const_string') + len(x)"
                    if (

View on GitHub (pinned to df599052da)

Solutions

  1. Report the bug to https://github.com/pola-rs/polars/issues including the function source and the {inst!r} object from the traceback
  2. Rewrite the lambda using native polars expressions (no map_elements), which skips bytecode translation entirely
  3. Upgrade polars to the newest release, where the new Python opcodes are usually catalogued quickly
  4. Pin Python to a version supported by your polars release

Example fix

# before
s.map_elements(lambda v: v.lower() + '!', return_dtype=pl.String)

# after
pl.col('s').str.to_lowercase() + '!'
Defensive patterns

Strategy: fallback

Try / catch

try:
    out = s.map_elements(fn, return_dtype=pl.Int64)
except AssertionError as e:
    if 'unrecognised op name' in str(e):
        out = None  # skip translation; rewrite fn with native expressions instead
    else:
        raise

Prevention

When it happens

Trigger: Calling .map_elements(lambda x: ...) (or the map deprecation path) on a newly released Python version whose bytecode uses opnames unknown to the installed polars build; functions using unusual bytecode-emitting constructs that disassemble into unmapped instructions.

Common situations: Running polars on a just-released CPython (new opcodes like the adaptive-specialized families); CI images upgraded to newer Python than polars supports; after a bytecode-affecting change, e.g. walrus/comprehension changes in a new minor release.

Related errors


AI-assisted analysis of pola-rs/polars@df599052da (2026-08-16). Data as JSON: /api/errors/fb2af4c671bcca2b. Report an issue: GitHub.