class_docstr: File writer for TFRecord dataset.
  
  TFRecordWriter serializes tensors in tf.Example schema and write them
  into files in TFRecord format. The written file can be loaded with
  tf.data.TFRecordDataset.
class_docstr_tok: ["File","writer","for","TFRecord","dataset",".","TFRecordWriter","serializes","tensors","in","tf.Example","schema","and","write","them","into","files","in","TFRecord","format",".","The","written","file","can","be","loaded","with","tf.data.TFRecordDataset","."]
docstr: Build tf.Example parsing config
  
  Args:
    name: A str feature name.
    generator: Generator for this tensor.
  
  Returns:
    tf.io.FixedLenFeature if generator is TensorGenerator.
    tf.io.SparseFeature if generator is SparseTensorGenerator.
    tf.io.VarLenFeature if generator is VarlenTensorGenerator.
  
  Raises:
    TypeError: if generator is not TensorGenerator, SparseTensorGenerator, or VarlenTensorGenerator.
docstr_tok: ["Build","tf.Example","parsing","config","Args",":","name",":","A","str","feature","name",".","generator",":","Generator","for","this","tensor",".","Returns",":","tf.io.FixedLenFeature","if","generator","is","TensorGenerator",".","tf.io.SparseFeature","if","generator","is","SparseTensorGenerator",".","tf.io.VarLenFeature","if","generator","is","VarlenTensorGenerator",".","Raises",":","TypeError",":","if","generator","is","not","TensorGenerator",",","SparseTensorGenerator",",","or","VarlenTensorGenerator","."]
code: def _build_tf_example_parsing_config(self, name, generator):
      """Build tf.Example parsing config
  
      Args:
        name: A str feature name.
        generator: Generator for this tensor.
  
      Returns:
        tf.io.FixedLenFeature if generator is TensorGenerator.
        tf.io.SparseFeature if generator is SparseTensorGenerator.
        tf.io.VarLenFeature if generator is VarlenTensorGenerator.
  
      Raises:
        TypeError: if generator is not TensorGenerator, SparseTensorGenerator, or VarlenTensorGenerator.
      """
      spec = generator.spec
      example_dtype = self._map_tensor_dtype_to_example_dtype(
          spec.dtype
      )
      if isinstance(spec, tf.TensorSpec):
          return tf.io.FixedLenFeature(
              shape=spec.shape, dtype=example_dtype
          )
      elif isinstance(spec, tf.SparseTensorSpec):
          if (
              issubclass(
                  generator.get_generator_cls(),
                  VarLenTensorGeneratorBase,
              )
              and spec.shape.rank == 1
          ):
              return tf.io.VarLenFeature(dtype=example_dtype)
          elif (
              issubclass(
                  generator.get_generator_cls(),
                  SparseTensorGeneratorBase,
              )
              and spec.shape.is_fully_defined()
          ):
              index_name = name + TFRecordWriter._SPARSE_INDICES_SUFFIX
              rank = len(spec.shape)
              index_key = [f"{index_name}{dim}" for dim in range(rank)]
              value_key = name + TFRecordWriter._SPARSE_VALUES_SUFFIX
              return tf.io.SparseFeature(
                  index_key=index_key,
                  value_key=value_key,
                  dtype=example_dtype,
                  size=spec.shape,
              )
          else:
              raise ValueError(
                  "SparseTensorSpec shape must be either a 1D varlen tensor from VarLenTensorGenerator "
                  f"or fully defined sparse tensor from SparseTensorGenerator. Found {spec}"
              )
      else:
          raise TypeError(
              f"Spec {spec} is not supported in TFRecordWriter."
          )
  
file_path: io/tests/test_atds_avro/utils/tf_record_writer.py
imports: import os
  from tests.test_atds_avro.utils.generator.tensor_generator import TensorGeneratorBase
  from tests.test_atds_avro.utils.generator.sparse_tensor_generator import SparseTensorGeneratorBase
  from tests.test_atds_avro.utils.generator.varlen_tensor_generator import VarLenTensorGeneratorBase
  import numpy
  import tensorflow
  from tests.test_atds_avro.utils.file_writer import FileWriter
label_desc: Use image node_id 10 for calling the TFRecordWriter obj's underlying member method code with example usage: obj._build_tf_example_parsing_config(name, generator) and returns: tf, tf, tf