code: def test_read_with_invalid_schema(
      ray_start_regular_shared,
      tmp_path,
  ):
      from tensorflow_metadata.proto.v0 import schema_pb2
  
      # The dataset we will write to a .tfrecords file.
      ds = ray.data.from_items(data_partial(True), parallelism=1)
      expected_records = tf_records_partial()
  
      # Build fake schema proto with missing/incorrect field name
      tf_schema_wrong_name = schema_pb2.Schema()
      schema_feature = tf_schema_wrong_name.feature.add()
      schema_feature.name = "wrong_name"
      schema_feature.type = schema_pb2.FeatureType.INT
  
      # Build a fake schema proto with incorrect type
      tf_schema_wrong_type = _features_to_schema(
          expected_records[0].features
      )
      for schema_feature in tf_schema_wrong_type.feature:
          if schema_feature.name == "bytes_item":
              schema_feature.type = schema_pb2.FeatureType.INT
              break
  
      # Writing with incorrect schema should raise a `ValueError`
      with pytest.raises(ValueError) as e:
          ds.write_tfrecords(tmp_path, tf_schema=tf_schema_wrong_name)
      assert "Found extra unexpected feature" in str(e.value.args[0])
  
      with pytest.raises(ValueError) as e:
          ds.write_tfrecords(tmp_path, tf_schema=tf_schema_wrong_type)
      assert str(e.value.args[0]) == (
          "Schema field type mismatch during write: "
          "specified type is int, but underlying type is bytes"
      )
  
      # Complete a valid write, then try reading with incorrect schema,
      # which should raise a `ValueError`.
      ds.write_tfrecords(tmp_path)
      with pytest.raises(ValueError) as e:
          ray.data.read_tfrecords(
              tmp_path, tf_schema=tf_schema_wrong_name
          ).materialize()
      assert "Found extra unexpected feature" in str(e.value.args[0])
  
      with pytest.raises(ValueError) as e:
          ray.data.read_tfrecords(
              tmp_path, tf_schema=tf_schema_wrong_type
          ).materialize()
      assert str(e.value.args[0]) == (
          "Schema field type mismatch during read: "
          "specified type is int, but underlying type is bytes"
      )
  
imports: import json
  import os
  from typing import TYPE_CHECKING
  import numpy
  import pytest
  from pandas.api.types import is_float_dtype, is_int64_dtype, is_object_dtype
  import ray
  from ray.tests.conftest import *
label_desc: Use image node_id 15 for calling a global function with example usage: test_read_with_invalid_schema(ray_start_regular_shared, tmp_path) without return types