code: def infer_schema(
      statistics: statistics_pb2.DatasetFeatureStatisticsList,
      infer_feature_shape: bool = True,
      max_string_domain_size: int = 100,
      schema_transformations: Optional[
          List[
              Callable[
                  [
                      schema_pb2.Schema,
                      statistics_pb2.DatasetFeatureStatistics,
                  ],
                  schema_pb2.Schema,
              ]
          ]
      ] = None,
  ) -> schema_pb2.Schema:
      """Infers schema from the input statistics.
  
      Args:
        statistics: A DatasetFeatureStatisticsList protocol buffer. Schema inference
          is currently supported only for lists with a single
          DatasetFeatureStatistics proto or lists with multiple
          DatasetFeatureStatistics protos corresponding to data slices that include
          the default slice (i.e., the slice with all examples). If a list with
          multiple DatasetFeatureStatistics protos is used, this function will infer
          the schema from the statistics corresponding to the default slice.
        infer_feature_shape: A boolean to indicate if shape of the features need to
          be inferred from the statistics.
        max_string_domain_size: Maximum size of the domain of a string feature in
            order to be interpreted as a categorical feature.
        schema_transformations: List of transformation functions to apply to the
            auto-inferred schema. Each transformation function should take the
            schema and statistics as input and should return the transformed schema.
            The transformations are applied in the order provided in the list.
  
      Returns:
        A Schema protocol buffer.
  
      Raises:
        TypeError: If the input argument is not of the expected type.
        ValueError: If the input statistics proto contains multiple datasets, none
            of which corresponds to the default slice.
      """
      if not isinstance(
          statistics, statistics_pb2.DatasetFeatureStatisticsList
      ):
          raise TypeError(
              "statistics is of type %s, should be "
              "a DatasetFeatureStatisticsList proto."
              % type(statistics).__name__
          )
  
      # This will raise an exception if there are multiple datasets, none of which
      # corresponds to the default slice.
      dataset_statistics = _get_default_dataset_statistics(statistics)
  
      # dataset_statistics may include stats for composite features like
      # SparseFeatures and WeightedFeatures. We cannot infer a useful schema from
      # these stats, so we remove them at the start.
      dataset_statistics = _remove_features_missing_common_stats(
          dataset_statistics
      )
  
      schema_proto_string = (
          pywrap_tensorflow_data_validation.InferSchema(
              tf.compat.as_bytes(
                  dataset_statistics.SerializeToString()
              ),
              max_string_domain_size,
              infer_feature_shape,
          )
      )
  
      # Parse the serialized Schema proto.
      result = schema_pb2.Schema()
      result.ParseFromString(schema_proto_string)
  
      _may_be_set_legacy_flag(result)
  
      if schema_transformations is not None:
          for transformation_fn in schema_transformations:
              result = transformation_fn(result, statistics.datasets[0])
      return result
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import itertools
  import logging
  from typing import Callable, Iterable, List, Optional, Text, Tuple, Set
  import apache_beam
  import pyarrow
  import tensorflow
  from tensorflow_data_validation import constants
  from tensorflow_data_validation import types
  from tensorflow_data_validation.anomalies.proto import custom_validation_config_pb2
  from tensorflow_data_validation.anomalies.proto import validation_config_pb2
  from tensorflow_data_validation.anomalies.proto import validation_metadata_pb2
  from tensorflow_data_validation.api import validation_options
  from tensorflow_data_validation.pywrap.tensorflow_data_validation_extension import validation
  from tensorflow_data_validation.skew import feature_skew_detector
  from tensorflow_data_validation.skew.protos import feature_skew_results_pb2
  from tensorflow_data_validation.statistics import stats_impl
  from tensorflow_data_validation.statistics import stats_options
  from tensorflow_data_validation.utils import anomalies_util
  from tensorflow_data_validation.utils import slicing_util
  from tensorflow_data_validation.utils import stats_util
  from tensorflow_metadata.proto.v0 import anomalies_pb2
  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: infer_schema(statistics, infer_feature_shape, max_string_domain_size, schema_transformations) and returns: result