code: def test_struct():
      ty = pa.struct(
          [pa.field("x", pa.int16()), pa.field("y", pa.float32())]
      )
  
      v = {"x": 2, "y": 3.5}
      s = pa.scalar(v, type=ty)
      assert list(s) == list(s.keys()) == ["x", "y"]
      assert list(s.values()) == [
          pa.scalar(2, type=pa.int16()),
          pa.scalar(3.5, type=pa.float32()),
      ]
      assert list(s.items()) == [
          ("x", pa.scalar(2, type=pa.int16())),
          ("y", pa.scalar(3.5, type=pa.float32())),
      ]
      assert "x" in s
      assert "y" in s
      assert "z" not in s
      assert 0 not in s
  
      assert s.as_py() == v
      assert repr(s) != repr(v)
      assert repr(s.as_py()) == repr(v)
      assert len(s) == 2
      assert isinstance(s["x"], pa.Int16Scalar)
      assert isinstance(s["y"], pa.FloatScalar)
      assert s["x"].as_py() == 2
      assert s["y"].as_py() == 3.5
  
      with pytest.raises(KeyError):
          s["nonexistent"]
  
      s = pa.scalar(None, type=ty)
      assert list(s) == list(s.keys()) == ["x", "y"]
      assert s.as_py() is None
      assert "x" in s
      assert "y" in s
      assert isinstance(s["x"], pa.Int16Scalar)
      assert isinstance(s["y"], pa.FloatScalar)
      assert s["x"].is_valid is False
      assert s["y"].is_valid is False
      assert s["x"].as_py() is None
      assert s["y"].as_py() is None
  
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 36 for calling a global function with example usage: test_struct() without return types