code: def _to_patsy_env(environment: Environment) -> EvalEnvironment:
      """
      Convert a plotnine environment to a patsy environment
      """
      from patsy.eval import EvalEnvironment
  
      eval_env = EvalEnvironment(environment.namespaces)
      return eval_env
  
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 17 for calling a global function with example usage: _to_patsy_env(environment) and returns: eval_env