{"record":{"id":"9d991041d72e7db8","repo":"pola-rs/polars","slug":"todo-frame-map-function-parsing","errorCode":null,"errorMessage":"TODO: 'frame' map-function parsing","messagePattern":"TODO: 'frame' map-function parsing","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/_utils/udfs.py","lineNumber":1237,"sourceCode":"def warn_on_inefficient_map(\n    function: Callable[[Any], Any], columns: list[str], map_target: MapTarget\n) -> None:\n    \"\"\"\n    Generate `PolarsInefficientMapWarning` on poor usage of a `map` function.\n\n    Parameters\n    ----------\n    function\n        The function passed to `map`.\n    columns\n        The column name(s) of the original object; in the case of an `Expr` this\n        will be a list of length 1, containing the expression's root name.\n    map_target\n        The target of the `map` call. One of `\"expr\"`, `\"frame\"`, or `\"series\"`.\n    \"\"\"\n    if map_target == \"frame\":\n        msg = \"TODO: 'frame' map-function parsing\"\n        raise NotImplementedError(msg)\n\n    # note: we only consider simple functions with a single col/param\n    col: str = columns and columns[0]  # type: ignore[assignment]\n    if not col and col != \"\":\n        return None\n\n    # the parser introspects function bytecode to determine if we can\n    # rewrite as a (much) more optimal native polars expression instead\n    if (parser := _BYTECODE_PARSER_CACHE_.get(key := (function, map_target))) is None:\n        parser = BytecodeParser(function, map_target)\n        _BYTECODE_PARSER_CACHE_[key] = parser\n\n    if parser.can_attempt_rewrite():\n        parser.warn(col)\n    else:\n        # handle bare numpy/json functions\n        module, suggestion = _raw_function_meta(function)\n        if module and suggestion:","sourceCodeStart":1219,"sourceCodeEnd":1255,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/_utils/udfs.py#L1219-L1255","documentation":"warn_on_inefficient_map analyzes map-family calls to warn about inefficient Python UDFs, but parsing a 'frame' map target (DataFrame.map) is explicitly unimplemented and raises NotImplementedError('TODO: 'frame' map-function parsing'). It is a guard against analyzing a case the parser never learned to handle.","triggerScenarios":"Calling map_elements / the warning hook with map_target == \"frame\" — i.e. a DataFrame-level map function — which immediately raises before any analysis.","commonSituations":"Applying df.map(...) with a Python function and hitting the analysis path; library code paths that route frame-level maps into the UDF warning machinery in a newer/older polars version.","solutions":["Don't use DataFrame.map with Python functions; express the transformation with native expressions or Expr.map_elements.","Wrap the call site so frame-level maps bypass the parser, or upgrade polars where this path may have changed.","Report upstream if you need frame-map efficiency analysis."],"exampleFix":"// before\ndf.map(row_fn)\n// after\ndf.with_columns((pl.col('a') + pl.col('b')).alias('c'))","handlingStrategy":"validation","validationCode":"# guard at the call site\nif map_target == 'frame':\n    raise SkipAnalysis('frame-level map parsing not supported')","typeGuard":"def is_parseable_map_target(t) -> bool:\n    return t in ('expr', 'series')","tryCatchPattern":"try:\n    warn_on_inefficient_map(fn, columns=cols, map_target='frame')\nexcept NotImplementedError:\n    pass  # skip efficiency analysis for frame maps","preventionTips":["Route frame-level maps around the UDF analyzer","Prefer Expr.map_elements over df.map","Keep polars updated for analysis coverage changes"],"tags":["python","polars","udf","frame-map"],"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"}