class_docstr: Translates Instruction bytecode to a polars expression string.
class_docstr_tok: ["Translates","Instruction","bytecode","to","a","polars","expression","string","."]
docstr: Take stack entry value and convert to polars expression string.
code: 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 = 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)"
                  pfx = "np." if op in _NUMPY_FUNCTIONS else ""
                  return f"{pfx}{op}({e1})"
              return f"{op}{e1}"
          else:
              e2 = self._expr(
                  value.right_operand, col, param_name, depth + 1
              )
              if op in ("is", "is not") and value[2] == "None":
                  not_ = "" if op == "is" else "not_"
                  return f"{e1}.is_{not_}null()"
              elif op in ("in", "not in"):
                  not_ = "" if op == "in" else "~"
                  return (
                      f"{not_}({e1}.is_in({e2}))"
                      if " " in e1
                      else f"{not_}{e1}.is_in({e2})"
                  )
              elif op == "replace":
                  if not self._caller_variables:
                      self._caller_variables.update(
                          _get_all_caller_variables()
                      )
                      if not isinstance(
                          self._caller_variables.get(e1, None), dict
                      ):
                          raise NotImplementedError(
                              "require dict mapping"
                          )
                  return f"{e2}.{op}({e1})"
              elif op == "<<":
                  # Result of 2**e2 might be float is e2 was negative.
                  # But, if e1 << e2 was valid, then e2 must have been positive.
                  # Hence, the output of 2**e2 can be safely cast to Int64, which
                  # may be necessary if chaining operations which assume Int64 output.
                  return f"({e1}*2**{e2}).cast(pl.Int64)"
              elif op == ">>":
                  # Motivation for the cast is the same as in the '<<' case above.
                  return f"({e1} / 2**{e2}).cast(pl.Int64)"
              else:
                  expr = f"{e1} {op} {e2}"
                  return f"({expr})" if depth else expr
  
      elif value == param_name:
          return f'pl.col("{col}")'
  
      return value
  
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 4 for calling the InstructionTranslator obj's underlying member method code with example usage: obj._expr(value, col, param_name, depth) and returns: value, op, e1, str, col, str, pfx, op, str, e1, str, e1, str, not_, str, e1, str, op, call, str, e1, str, op, call, unknown, e2, str, op, str, e1, str, str, e1, str, e2, str, str, e1, str, e2, str, unknown