code: def test_read_tfrecords(
      with_tf_schema,
      ray_start_regular_shared,
      tmp_path,
  ):
      import pandas as pd
      import tensorflow as tf
  
      example = tf_records_empty()[0]
  
      tf_schema = None
      if with_tf_schema:
          tf_schema = _features_to_schema(example.features)
  
      path = os.path.join(tmp_path, "data.tfrecords")
      with tf.io.TFRecordWriter(path=path) as writer:
          writer.write(example.SerializeToString())
  
      ds = ray.data.read_tfrecords(path, tf_schema=tf_schema)
      df = ds.to_pandas()
      # Protobuf serializes features in a non-deterministic order.
      if with_tf_schema:
          assert is_object_dtype(dict(df.dtypes)["int_item"])
      else:
          assert is_int64_dtype(dict(df.dtypes)["int_item"])
      assert is_object_dtype(dict(df.dtypes)["int_list"])
      assert is_object_dtype(dict(df.dtypes)["int_partial"])
      assert is_object_dtype(dict(df.dtypes)["int_empty"])
  
      if with_tf_schema:
          assert is_object_dtype(dict(df.dtypes)["float_item"])
          assert is_object_dtype(dict(df.dtypes)["float_partial"])
      else:
          assert is_float_dtype(dict(df.dtypes)["float_item"])
          assert is_float_dtype(dict(df.dtypes)["float_partial"])
      assert is_object_dtype(dict(df.dtypes)["float_list"])
      assert is_object_dtype(dict(df.dtypes)["float_empty"])
  
      # In both cases, bytes are of `object` dtype in pandas
      assert is_object_dtype(dict(df.dtypes)["bytes_item"])
      assert is_object_dtype(dict(df.dtypes)["bytes_partial"])
      assert is_object_dtype(dict(df.dtypes)["bytes_list"])
      assert is_object_dtype(dict(df.dtypes)["bytes_empty"])
  
      # strings are of `object` dtype in pandas
      assert is_object_dtype(dict(df.dtypes)["string_item"])
      assert is_object_dtype(dict(df.dtypes)["string_partial"])
      assert is_object_dtype(dict(df.dtypes)["string_list"])
      assert is_object_dtype(dict(df.dtypes)["string_empty"])
  
      # If the schema is specified, we should not perform the
      # automatic unwrapping of single-element lists.
      if with_tf_schema:
          assert isinstance(df["int_item"], pd.Series)
          assert df["int_item"].tolist() == [[1]]
      else:
          assert list(df["int_item"]) == [1]
      assert np.array_equal(df["int_list"][0], np.array([2, 2, 3]))
      assert np.array_equal(
          df["int_partial"][0], np.array([], dtype=np.int64)
      )
      assert np.array_equal(
          df["int_empty"][0], np.array([], dtype=np.int64)
      )
  
      if with_tf_schema:
          assert isinstance(df["float_item"], pd.Series)
          assert df["float_item"].tolist() == [[1.0]]
      else:
          assert list(df["float_item"]) == [1.0]
      assert np.array_equal(
          df["float_list"][0], np.array([2.0, 3.0, 4.0])
      )
      assert list(df["float_partial"]) == [1.0]
      assert np.array_equal(
          df["float_empty"][0], np.array([], dtype=np.float32)
      )
  
      if with_tf_schema:
          assert isinstance(df["bytes_item"], pd.Series)
          assert df["bytes_item"].tolist() == [[b"abc"]]
          assert isinstance(df["string_item"], pd.Series)
          assert df["string_item"].tolist() == [
              [b"uvw"]
          ]  # strings are read as bytes
      else:
          assert list(df["bytes_item"]) == [b"abc"]
          assert list(df["string_item"]) == [b"uvw"]
      assert np.array_equal(
          df["bytes_list"][0], np.array([b"def", b"1234"])
      )
      assert np.array_equal(
          df["bytes_partial"][0], np.array([], dtype=np.bytes_)
      )
      assert np.array_equal(
          df["bytes_empty"][0], np.array([], dtype=np.bytes_)
      )
  
      assert np.array_equal(
          df["string_list"][0], np.array([b"xyz", b"999"])
      )
      assert np.array_equal(
          df["string_partial"][0], np.array([], dtype=np.bytes_)
      )
      assert np.array_equal(
          df["string_empty"][0], np.array([], dtype=np.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 7 for calling a global function with example usage: test_read_tfrecords(with_tf_schema, ray_start_regular_shared, tmp_path) without return types