code: def sample(
      data: DataType,
      n: Optional[int] = None,
      frac: Optional[float] = None,
  ) -> Optional[
      Union[pd.DataFrame, Dict[str, Sequence], "pyarrow.lib.Table"]
  ]:
      """Reduce the size of the data model by sampling without replacement."""
      check_data_type(data)
      if isinstance(data, pd.DataFrame):
          return data.sample(n=n, frac=frac)
      elif isinstance(data, dict):
          if "values" in data:
              values = data["values"]
              if not n:
                  if frac is None:
                      raise ValueError(
                          "frac cannot be None if n is None and data is a dictionary"
                      )
                  n = int(frac * len(values))
              values = random.sample(values, n)
              return {"values": values}
          else:
              # Maybe this should raise an error or return something useful?
              return None
      elif hasattr(data, "__dataframe__"):
          # experimental interchange dataframe support
          pi = import_pyarrow_interchange()
          pa_table = pi.from_dataframe(data)
          if not n:
              if frac is None:
                  raise ValueError(
                      "frac cannot be None if n is None with this data input type"
                  )
              n = int(frac * len(pa_table))
          indices = random.sample(range(len(pa_table)), n)
          return pa_table.take(indices)
      else:
          # Maybe this should raise an error or return something useful? Currently,
          # if data is of type SupportsGeoInterface it lands here
          return None
  
imports: import json
  import os
  import random
  import hashlib
  import warnings
  from typing import Union, MutableMapping, Optional, Dict, Sequence, TYPE_CHECKING, List
  import pandas
  from toolz import curried
  from typing import TypeVar
  from ._importers import import_pyarrow_interchange
  from .core import sanitize_dataframe, sanitize_arrow_table, DataFrameLike
  from .core import sanitize_geo_interface
  from .deprecation import AltairDeprecationWarning
  from .plugin_registry import PluginRegistry
  from typing import Protocol, TypedDict, Literal
label_desc: Use image node_id 2 for calling a global function with example usage: sample(data, n, frac) and returns: data, dict, None, pa_table, None