code: def loess(data, xseq, **params):
      """
      Loess smoothing
      """
      try:
          from skmisc.loess import loess as loess_klass
      except ImportError as e:
          msg = "For loess smoothing, install 'scikit-misc'"
          raise PlotnineError(msg) from e
  
      try:
          weights = data["weight"]
      except KeyError:
          weights = None
  
      kwargs = params["method_args"]
  
      extrapolate = min(xseq) < min(data["x"]) or max(xseq) > max(
          data["x"]
      )
      if "surface" not in kwargs and extrapolate:
          # Creates a loess model that allows extrapolation
          # when making predictions
          kwargs["surface"] = "direct"
          warnings.warn(
              "Making prediction outside the data range, "
              "setting loess control parameter `surface='direct'`.",
              PlotnineWarning,
          )
  
      if "span" not in kwargs:
          kwargs["span"] = params["span"]
  
      lo = loess_klass(data["x"], data["y"], weights, **kwargs)
      lo.fit()
  
      data = pd.DataFrame({"x": xseq})
  
      if params["se"]:
          alpha = 1 - params["level"]
          prediction = lo.predict(xseq, stderror=True)
          ci = prediction.confidence(alpha=alpha)
          data["se"] = prediction.stderr
          data["ymin"] = ci.lower
          data["ymax"] = ci.upper
      else:
          prediction = lo.predict(xseq, stderror=False)
  
      data["y"] = prediction.values  # noqa: PD011
  
      return data
  
imports: from __future__ import annotations
  import warnings
  from contextlib import suppress
  from typing import TYPE_CHECKING
  import numpy
  import pandas
  from .._utils import get_valid_kwargs
  from ..exceptions import PlotnineError, PlotnineWarning
label_desc: Use image node_id 11 for calling a global function with example usage: loess(data, xseq) and returns: data