code: def to_arrow_table(data):
      """
      Helper to convert a Pandas DataFrame to a PyArrow Table
  
      :param data: Pandas DataFrame
      :return: pyarrow.Table
      """
      import pyarrow as pa
  
      # Reset named index(ex) into a column
      if getattr(data.index, "name", None) is not None:
          data = data.reset_index()
  
      # Use pyarrow to infer schema from DataFrame
      for col, pd_type in data.dtypes.items():
          try:
              candidate_schema = pa.Schema.from_pandas(data[[col]])
  
              # Get inferred pyarrow type
              pa_type = candidate_schema.field(col).type
  
              # Convert Decimal columns to float
              if isinstance(
                  pa_type, (pa.Decimal128Type, pa.Decimal256Type)
              ):
                  data = data.assign(
                      **{col: data[col].astype("float64")}
                  )
  
          except pa.ArrowTypeError:
              if pd_type.kind == "O":
                  # Try converting object columns to strings to handle cases where a
                  # column has a mix of numbers and strings
                  data = data.assign(**{col: data[col].astype(str)})
  
          # Expand categoricals (not yet supported in VegaFusion)
          if isinstance(pd_type, pd.CategoricalDtype):
              cat = data[col].cat
              data = data.assign(**{col: cat.categories[cat.codes]})
  
          # Copy un-aligned columns to align them
          # (arrow-rs seems to have trouble with un-aligned arrays)
          values = getattr(data[col], "values", None)
          if values is not None:
              flags = getattr(values, "flags", None)
              if flags is not None:
                  try:
                      aligned = flags["ALIGNED"]
                      if not aligned:
                          data = data.assign(**{col: data[col].copy()})
                  except IndexError:
                      pass
  
      # Convert DataFrame to table. Keep index only if named
      preserve_index = bool(
          [name for name in getattr(data.index, "names", []) if name]
      )
      table = pa.Table.from_pandas(data, preserve_index=preserve_index)
  
      # Split into batches of desired size
      batches = table.to_batches(BATCH_SIZE)
      table = pa.Table.from_batches(batches, table.schema)
  
      return table
  
imports: import io
  import os
  import pathlib
  from hashlib import sha1
  from tempfile import NamedTemporaryFile
  import uuid
  import altair
  import pandas
  import pyarrow
  from weakref import WeakValueDictionary
label_desc: Use image node_id 1 for calling a global function with example usage: to_arrow_table(data) and returns: table