code: def generate_statistics_from_tfrecord(
      data_location: Text,
      output_path: Optional[bytes] = None,
      stats_options: options.StatsOptions = options.StatsOptions(),
      pipeline_options: Optional[PipelineOptions] = None,
  ) -> statistics_pb2.DatasetFeatureStatisticsList:
      """Compute data statistics from TFRecord files containing TFExamples.
  
      Runs a Beam pipeline to compute the data statistics and return the result
      data statistics proto.
  
      This is a convenience method for users with data in TFRecord format.
      Users with data in unsupported file/data formats, or users who wish
      to create their own Beam pipelines need to use the 'GenerateStatistics'
      PTransform API directly instead.
  
      Args:
        data_location: The location of the input data files.
        output_path: The file path to output data statistics result to. If None, we
          use a temporary directory. It will be a TFRecord file containing a single
          data statistics proto, and can be read with the 'load_statistics' API.
          If you run this function on Google Cloud, you must specify an
          output_path. Specifying None may cause an error.
        stats_options: `tfdv.StatsOptions` for generating data statistics.
        pipeline_options: Optional beam pipeline options. This allows users to
          specify various beam pipeline execution parameters like pipeline runner
          (DirectRunner or DataflowRunner), cloud dataflow service project id, etc.
          See https://cloud.google.com/dataflow/pipelines/specifying-exec-params for
          more details.
  
      Returns:
        A DatasetFeatureStatisticsList proto.
      """
      if output_path is None:
          output_path = os.path.join(
              tempfile.mkdtemp(), "data_stats.tfrecord"
          )
      output_dir_path = os.path.dirname(output_path)
      if not tf.io.gfile.exists(output_dir_path):
          tf.io.gfile.makedirs(output_dir_path)
  
      batch_size = stats_options.desired_batch_size
      # PyLint doesn't understand Beam PTransforms.
      # pylint: disable=no-value-for-parameter
      with beam.Pipeline(options=pipeline_options) as p:
          # Auto detect tfrecord file compression format based on input data
          # path suffix.
          _ = (
              p
              | "ReadData"
              >> (
                  tf_example_record.TFExampleRecord(
                      file_pattern=data_location,
                      schema=None,
                      telemetry_descriptors=[
                          "tfdv",
                          "generate_statistics_from_tfrecord",
                      ],
                  ).BeamSource(batch_size)
              )
              | "GenerateStatistics"
              >> stats_api.GenerateStatistics(stats_options)
              | "WriteStatsOutput"
              >> (stats_api.WriteStatisticsToTFRecord(output_path))
          )
      return stats_util.load_statistics(output_path)
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import copy
  import csv
  import gzip
  import io
  import multiprocessing
  import os
  import tempfile
  from typing import Any, List, Optional, Text, cast
  import apache_beam
  from apache_beam.io.filesystem import CompressionTypes
  from apache_beam.options.pipeline_options import PipelineOptions
  from joblib import delayed
  from joblib import Parallel
  import numpy
  from pandas import DataFrame
  import pyarrow
  import tensorflow
  from tensorflow_data_validation import constants
  from tensorflow_data_validation import types
  from tensorflow_data_validation.api import stats_api
  from tensorflow_data_validation.coders import csv_decoder
  from tensorflow_data_validation.statistics import stats_impl
  from tensorflow_data_validation.statistics import stats_options
  from tensorflow_data_validation.statistics.generators import stats_generator
  from tensorflow_data_validation.utils import stats_util
  from tfx_bsl.arrow import table_util
  from tfx_bsl.tfxio import tf_example_record
  from tensorflow_metadata.proto.v0 import schema_pb2
  from tensorflow_metadata.proto.v0 import statistics_pb2
label_desc: Use image node_id 1 for calling a global function with example usage: generate_statistics_from_tfrecord(data_location, output_path, stats_options, pipeline_options) and returns: stats_util