code: def set_timezone(tz: str) -> Generator[None, None, None]:
      """
      Context manager for temporarily setting a timezone.
  
      Parameters
      ----------
      tz : str
          A string representing a valid timezone.
  
      Examples
      --------
      >>> from datetime import datetime
      >>> from dateutil.tz import tzlocal
      >>> tzlocal().tzname(datetime(2021, 1, 1))  # doctest: +SKIP
      'IST'
  
      >>> with set_timezone('US/Eastern'):
      ...     tzlocal().tzname(datetime(2021, 1, 1))
      ...
      'EST'
      """
      import time
  
      def setTZ(tz) -> None:
          if tz is None:
              try:
                  del os.environ["TZ"]
              except KeyError:
                  pass
          else:
              os.environ["TZ"] = tz
              time.tzset()
  
      orig_tz = os.environ.get("TZ")
      setTZ(tz)
      try:
          yield
      finally:
          setTZ(orig_tz)
  
file_path: pandas/pandas/_testing/contexts.py
imports: from __future__ import annotations
  from contextlib import contextmanager
  import os
  from pathlib import Path
  import tempfile
  from typing import IO, TYPE_CHECKING, Any
  import uuid
  from pandas._config import using_copy_on_write
  from pandas.compat import PYPY
  from pandas.errors import ChainedAssignmentError
  from pandas import set_option
  from pandas.io.common import get_handle
label_desc: Use image node_id 2 for calling a global function with example usage: set_timezone(tz) without return types