{"record":{"id":"a604c0f3a5530972","repo":"pola-rs/polars","slug":"unexpected-or-unrecognised-op-name-opname-please-report-a","errorCode":null,"errorMessage":"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}","messagePattern":"unexpected or unrecognised op name \\((.+?)\\)\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(.+?)","errorType":"exception","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/_utils/udfs.py","lineNumber":675,"sourceCode":"            return OpNames.CONTROL_FLOW[opname]\n        elif inst.argrepr:\n            return inst.argrepr\n        elif opname == \"IS_OP\":\n            return \"is not\" if inst.argval else \"is\"\n        elif opname == \"CONTAINS_OP\":\n            return \"not in\" if inst.argval else \"in\"\n        elif opname in OpNames.UNARY:\n            return OpNames.UNARY[opname]\n        elif opname == \"BINARY_SUBSCR\":\n            return \"replace_strict\"\n        else:\n            msg = (\n                f\"unexpected or unrecognised op name ({opname})\\n\\n\"\n                \"Please report a bug to https://github.com/pola-rs/polars/issues \"\n                \"with the content of function you were passing to the `map` \"\n                f\"expression and the following instruction object:\\n{inst!r}\"\n            )\n            raise AssertionError(msg)\n\n    def _expr(self, value: StackEntry, col: str, param_name: str, depth: int) -> str:\n        \"\"\"Take stack entry value and convert to polars expression string.\"\"\"\n        if isinstance(value, StackValue):\n            op = _RE_STRIP_BOOL.sub(r\"\\1\", value.operator)\n            e1 = self._expr(value.left_operand, col, param_name, depth + 1)\n            if value.operator_arity == 1:\n                if op not in OpNames.UNARY_VALUES:\n                    if e1.startswith(\"pl.col(\"):\n                        call = \"\" if op.endswith(\")\") else \"()\"\n                        return f\"{e1}.{op}{call}\"\n                    if e1[0] in OpNames.UNARY_VALUES and e1[1:].startswith(\"pl.col(\"):\n                        call = \"\" if op.endswith(\")\") else \"()\"\n                        return f\"({e1}).{op}{call}\"\n\n                    # support use of consts as numpy/builtin params, eg:\n                    # \"np.sin(3) + np.cos(x)\", or \"len('const_string') + len(x)\"\n                    if (","sourceCodeStart":657,"sourceCodeEnd":693,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/_utils/udfs.py#L657-L693","documentation":"During bytecode-to-expression translation the parser encounters a disassembled op whose name it has no rule for. It raises AssertionError telling the user to report the bug upstream with the function passed to map_elements and the offending instruction object. It signals a gap in the opcode coverage of the UDF parser.","triggerScenarios":"Passing to map_elements a function whose bytecode contains an opcode the parser doesn't handle (unusual operators, exotic constructs like complex comprehensions, async, or newer CPython opcodes); triggered from op() via _to_intermediate_stack/_height_preserving.","commonSituations":"Upgrading Python (new opcodes) while using an older polars; using advanced Python features inside a UDF (walrus, matrix ops, custom __mul__ objects); parser hit on the public to_expression path.","solutions":["Rewrite the UDF with simpler arithmetic/logic the parser supports, or replace with native polars expressions.","Pin/upgrade polars to a version matching your Python version's opcode set.","Report the bug to https://github.com/pola-rs/polars/issues including the function and instruction object from the message."],"exampleFix":"// before\npl.col('a').map_elements(lambda x: x @ M)\n// after\npl.col('a').map_elements(simple_scalar_fn)  # or native: pl.col('a') * 2","handlingStrategy":"try-catch","validationCode":"def parser_safe(fn):\n    import dis\n    try:\n        list(dis.get_instructions(fn))\n        return True\n    except TypeError:\n        return False","typeGuard":"def is_simple_function(fn) -> bool:\n    import types\n    return isinstance(fn, types.FunctionType) and not isinstance(fn, types.LambdaType) or callable(fn)","tryCatchPattern":"try:\n    out = df.select(pl.col('a').map_elements(fn))\nexcept AssertionError as e:\n    if 'unexpected or unrecognised op name' in str(e):\n        out = df.select(pl.col('a').map_elements(fn, skip_nulls=True)) if False else fallback(fn)  # compute outside parser","preventionTips":["Avoid exotic Python operators/features inside UDFs","Match polars version to your Python version","Report opcode gaps upstream with the instruction dump"],"tags":["python","polars","bytecode","unsupported-opcode"],"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"}