code: def to_arrow_ipc_bytes(data, stream=False):
      """
      Helper to convert a DataFrame to the Arrow IPC binary format
  
      :param data: Pandas DataFrame, pyarrow Table, or object that supports
          the DataFrame Interchange Protocol
      :param stream: If True, write IPC Stream format. If False (default), write ipc file format.
      :return: bytes
      """
      if isinstance(data, pd.DataFrame):
          table = to_arrow_table(data)
      elif isinstance(data, pa.Table):
          table = data
      elif hasattr(data, "__dataframe__"):
          pi = import_pyarrow_interchange()
          table = pi.from_dataframe(data)
      else:
          raise ValueError(
              f"Unsupported input to to_arrow_ipc_bytes: {type(data)}"
          )
      return arrow_table_to_ipc_bytes(table, stream=stream)
  
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 2 for calling a global function with example usage: to_arrow_ipc_bytes(data, stream) and returns: arrow_table_to_ipc_bytes