class_docstr: Introspect UDF bytecode and determine if we can rewrite as native expression.
class_docstr_tok: ["Introspect","UDF","bytecode","and","determine","if","we","can","rewrite","as","native","expression","."]
docstr: Generate warning that suggests an equivalent native polars expression.
code: def warn(
      self,
      col: str,
      suggestion_override: str | None = None,
      udf_override: str | None = None,
  ) -> None:
      """Generate warning that suggests an equivalent native polars expression."""
      # Import these here so that udfs can be imported without polars installed.
  
      from polars.exceptions import PolarsInefficientMapWarning
      from polars.utils.various import (
          find_stacklevel,
          in_terminal_that_supports_colour,
      )
  
      suggested_expression = suggestion_override or self.to_expression(
          col
      )
  
      if suggested_expression is not None:
          target_name = self._get_target_name(col, suggested_expression)
          func_name = udf_override or self._function.__name__ or "..."
          if func_name == "<lambda>":
              func_name = f"lambda {self._param_name}: ..."
  
          addendum = (
              'Note: in list.eval context, pl.col("") should be written as pl.element()'
              if 'pl.col("")' in suggested_expression
              else ""
          )
          if self._map_target == "expr":
              apitype = "expressions"
              clsname = "Expr"
          else:
              apitype = "series"
              clsname = "Series"
  
          before, after = (
              (
                  f"  \033[31m- {target_name}.map_elements({func_name})\033[0m\n",
                  f"  \033[32m+ {suggested_expression}\033[0m\n{addendum}",
              )
              if in_terminal_that_supports_colour()
              else (
                  f"  - {target_name}.map_elements({func_name})\n",
                  f"  + {suggested_expression}\n{addendum}",
              )
          )
          warnings.warn(
              f"\n{clsname}.map_elements is significantly slower than the native {apitype} API.\n"
              "Only use if you absolutely CANNOT implement your logic otherwise.\n"
              "Replace this expression...\n"
              f"{before}"
              "with this one instead:\n"
              f"{after}",
              PolarsInefficientMapWarning,
              stacklevel=find_stacklevel(),
          )
  
imports: from __future__ import annotations
  import datetime
  import dis
  import inspect
  import re
  import sys
  import warnings
  from bisect import bisect_left
  from collections import defaultdict
  from dis import get_instructions
  from inspect import signature
  from itertools import count, zip_longest
  from pathlib import Path
  from typing import TYPE_CHECKING, AbstractSet, Any, Callable, ClassVar, Iterator, Literal, NamedTuple, Union
label_desc: Use image node_id 13 for calling the BytecodeParser obj's underlying member method code with example usage: obj.warn(col, suggestion_override, udf_override) without return types