code: def filter_features(
      dataset_stats: statistics_pb2.DatasetFeatureStatistics,
      features_include: Optional[Sequence[str]] = None,
      features_exclude: Optional[Sequence[str]] = None,
  ) -> statistics_pb2.DatasetFeatureStatistics:
      """Filters features in a TFDV DatasetFeatureStatistics.
  
      Args:
        dataset_stats: The TFDV DatasetFeatureStatistics object.
        features_include: The names or paths of features to keep. Mutually exclusive
          with features_exclude.
        features_exclude: The names or paths of features to discard. Mutually
          exclusive with features_include.
  
      Returns:
        The DatasetFeatureStatisticsList with unwanted features filtered.
  
      Raises:
        ValueError: if both or neither of features_include and features_exclude are
          provided.
      """
  
      # Check that inputs are valid, and create filter function
      feature_name = (
          lambda feature: feature.name or feature.path.step[0]
      )
      if features_include and not features_exclude:
          include = (
              lambda feature: feature_name(feature) in features_include
          )
      elif features_exclude and not features_include:
          include = (
              lambda feature: feature_name(feature)
              not in features_exclude
          )
      else:
          raise ValueError(
              "filter_features() requires exactly one of "
              "features_include and features_exclude."
          )
  
      # Create new DatasetFeatureStatistics
      filtered_data_stats = statistics_pb2.DatasetFeatureStatistics()
      filtered_data_stats.CopyFrom(dataset_stats)
  
      # Filter out features, and write to DatasetFeatureStatistics
      filtered_features = [
          feature
          for feature in dataset_stats.features
          if include(feature)
      ]
      del filtered_data_stats.features[:]
      filtered_data_stats.features.extend(filtered_features)
  
      # Return filtered DatasetFeatureStatistics
      return filtered_data_stats
  
imports: import enum
  import os
  from typing import Any, Dict, Iterable, List, Optional, Sequence, Union
  import attr
  import ml_metadata
  import tensorflow
  import tensorflow_model_analysis
  from absl import logging
  from ml_metadata.proto import metadata_store_pb2
  from tensorflow_metadata.proto.v0 import statistics_pb2
  from model_card_toolkit import model_card
label_desc: Use image node_id 14 for calling a global function with example usage: filter_features(dataset_stats, features_include, features_exclude) and returns: filtered_data_stats