code: def evaluate(
      aesthetics: aes | dict[str, Any],
      data: pd.DataFrame,
      env: Environment,
  ) -> pd.DataFrame:
      """
      Evaluate aesthetics
  
      Parameters
      ----------
      aesthetics :
          Aesthetics to evaluate. They must be of the form {name: expr}
      data :
          Dataframe whose columns are/may-be variables in the aesthetic
          expressions i.e. it is a namespace with variables.
      env :
          Environment in which the aesthetics are evaluated
  
      Returns
      -------
      pd.DataFrame
          Dataframe of the form {name: result}, where each column is the
          result from evaluating an expression.
  
      Examples
      --------
      >>> from plotnine.mapping import Environment
      >>> var1 = 2
      >>> env = Environment.capture()
      >>> df = pd.DataFrame({'x': range(1, 6)})
      >>> aesthetics = {'y': 'x**var1'}
      >>> evaluate(aesthetics, df, env)
          y
      0   1
      1   4
      2   9
      3  16
      4  25
      """
      env = env.with_outer_namespace(AES_INNER_NAMESPACE)
  
      # Store evaluation results in a dict column in a dict
      evaled = {}
  
      # If a column name is not in the data, it is evaluated/transformed
      # in the environment of the call to ggplot
      for ae, col in aesthetics.items():
          if isinstance(col, str):
              if col in data:
                  evaled[ae] = data[col]
              else:
                  try:
                      new_val = env.eval(col, inner_namespace=data)
                  except Exception as e:
                      msg = _TPL_EVAL_FAIL.format(ae, col, str(e))
                      raise PlotnineError(msg) from e
  
                  try:
                      evaled[ae] = new_val
                  except Exception as e:
                      msg = _TPL_BAD_EVAL_TYPE.format(
                          ae, col, str(type(new_val)), str(e)
                      )
                      raise PlotnineError(msg) from e
  
          elif pdtypes.is_list_like(col):
              n = len(col)
              if len(data) and n != len(data) and n != 1:
                  msg = (
                      "Aesthetics must either be length one, "
                      "or the same length as the data"
                  )
                  raise PlotnineError(msg)
              evaled[ae] = col
          elif is_known_scalar(col):
              if not len(evaled):
                  col = [col]
              evaled[ae] = col
          else:
              msg = f"Do not know how to deal with aesthetic '{ae}'"
              raise PlotnineError(msg)
  
      # Using `type` preserves the subclass of pd.DataFrame
      index = data.index if len(data.index) and evaled else None
      evaled = type(data)(data=evaled, index=index)
      return evaled
  
file_path: plotnine/plotnine/mapping/evaluation.py
imports: from __future__ import annotations
  import numbers
  import typing
  import numpy
  import pandas
  import pandas.api.types
  from ..exceptions import PlotnineError
label_desc: Use image node_id 4 for calling a global function with example usage: evaluate(aesthetics, data, env) and returns: evaled