code: def test_union(pickle_module):
      # sparse
      arr = pa.UnionArray.from_sparse(
          pa.array([0, 0, 1, 1], type=pa.int8()),
          [pa.array(["a", "b", "c", "d"]), pa.array([1, 2, 3, 4])],
      )
      for s in arr:
          s.validate(full=True)
          assert isinstance(s, pa.UnionScalar)
          assert s.type.equals(arr.type)
          assert s.is_valid is True
          with pytest.raises(pa.ArrowNotImplementedError):
              pickle_module.loads(pickle_module.dumps(s))
  
      assert arr[0].type_code == 0
      assert arr[0].as_py() == "a"
      assert arr[1].type_code == 0
      assert arr[1].as_py() == "b"
      assert arr[2].type_code == 1
      assert arr[2].as_py() == 3
      assert arr[3].type_code == 1
      assert arr[3].as_py() == 4
  
      # dense
      arr = pa.UnionArray.from_dense(
          types=pa.array([0, 1, 0, 0, 1, 1, 0], type="int8"),
          value_offsets=pa.array([0, 0, 2, 1, 1, 2, 3], type="int32"),
          children=[
              pa.array([b"a", b"b", b"c", b"d"], type="binary"),
              pa.array([1, 2, 3], type="int64"),
          ],
      )
      for s in arr:
          s.validate(full=True)
          assert isinstance(s, pa.UnionScalar)
          assert s.type.equals(arr.type)
          assert s.is_valid is True
          with pytest.raises(pa.ArrowNotImplementedError):
              pickle_module.loads(pickle_module.dumps(s))
  
      assert arr[0].type_code == 0
      assert arr[0].as_py() == b"a"
      assert arr[5].type_code == 1
      assert arr[5].as_py() == 3
  
imports: import datetime
  import decimal
  import pytest
  import sys
  import weakref
  import numpy
  import pyarrow
  import pyarrow.compute
  from pyarrow.tests import util
label_desc: Use image node_id 41 for calling a global function with example usage: test_union(pickle_module) without return types