{"record":{"id":"fb2af4c671bcca2b","repo":"pola-rs/polars","slug":"unexpected-or-unrecognised-op-name-opname-n-np","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/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/_utils/udfs.py#L657-L693","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Report the bug to https://github.com/pola-rs/polars/issues including the function source and the {inst!r} object from the traceback","Rewrite the lambda using native polars expressions (no map_elements), which skips bytecode translation entirely","Upgrade polars to the newest release, where the new Python opcodes are usually catalogued quickly","Pin Python to a version supported by your polars release"],"exampleFix":"# before\ns.map_elements(lambda v: v.lower() + '!', return_dtype=pl.String)\n\n# after\npl.col('s').str.to_lowercase() + '!'","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    out = s.map_elements(fn, return_dtype=pl.Int64)\nexcept AssertionError as e:\n    if 'unrecognised op name' in str(e):\n        out = None  # skip translation; rewrite fn with native expressions instead\n    else:\n        raise","preventionTips":["Prefer native expressions over map_elements wherever possible","Pin the Python version in CI to one supported by your polars release","When a new CPython drops, upgrade polars early and report unmapped opnames upstream"],"tags":["polars","map-elements","bytecode","python-version","assertionerror","internal-bug"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}