code: def test_serialize(df, to_host):
      """This should hopefully replace all functions below"""
      a = df()
      if "cudf" not in type(a).__module__:
          a = cudf.from_pandas(a)
      if to_host:
          header, frames = a.host_serialize()
      else:
          header, frames = a.device_serialize()
      msgpack.dumps(
          header
      )  # ensure that header is msgpack serializable
      ndevice = 0
      for frame in frames:
          if hasattr(frame, "__cuda_array_interface__"):
              ndevice += 1
      # Indices etc. will not be DeviceNDArray
      # but data should be...
      if to_host:
          assert ndevice == 0
      elif hasattr(df, "_cols"):
          assert ndevice >= len(df._data)
      else:
          # If there are frames, something should be on the device
          assert ndevice > 0 or not frames
  
      typ = type(a)
      b = typ.deserialize(header, frames)
      assert_eq(a, b)
  
imports: import pickle
  import msgpack
  import numpy
  import pandas
  import pytest
  import cudf
  from cudf.testing import _utils
  from cudf.testing._utils import assert_eq
label_desc: Use image node_id 1 for calling a global function with example usage: test_serialize(df, to_host) without return types