code: def remove_anomaly_types(
      anomalies: anomalies_pb2.Anomalies,
      types_to_remove: FrozenSet["anomalies_pb2.AnomalyInfo.Type"],
  ) -> None:
      """Removes the specified types of anomaly reasons from an Anomalies proto.
  
      If all reasons for a given feature's anomalies are removed, the entire feature
      will be removed from the Anomalies proto.
  
      Args:
        anomalies: The Anomalies proto from which to remove anomaly reasons of
          the specified types.
        types_to_remove: A set of the types of reasons to remove.
      """
      features_to_remove = []
      for feature_name, anomaly_info in anomalies.anomaly_info.items():
          retained_reasons = [
              reason
              for reason in anomaly_info.reason
              if reason.type not in types_to_remove
          ]
  
          # Clear the diff regions entirely since we do not have a way of readily
          # separating the comparisons that are attributable to the retained reasons
          # from those that are attributable to the removed reasons.
          anomaly_info.ClearField("diff_regions")
          anomaly_info.ClearField("reason")
          if retained_reasons:
              # If there are anomaly reasons that are retained, update the anomaly info
              # for the feature to include only those retained reasons.
              anomaly_info.reason.extend(retained_reasons)
              # Replace the description and short_description based on the reasons that
              # are retained.
              (
                  updated_description,
                  updated_short_description,
              ) = _make_updated_descriptions(retained_reasons)
              anomaly_info.description = updated_description
              anomaly_info.short_description = updated_short_description
  
          else:
              # If there are no anomaly types that are retained for a given feature,
              # remove that feature from the anomaly_info map entirely.
              features_to_remove.append(feature_name)
  
      for feature_name in features_to_remove:
          del anomalies.anomaly_info[feature_name]
  
file_path: data-validation/tensorflow_data_validation/utils/anomalies_util.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from typing import Iterable, FrozenSet, List, Text, Tuple
  import pyarrow
  from tensorflow_data_validation import types
  from tensorflow_data_validation.utils import io_util
  from google.protobuf import text_format
  from tensorflow_metadata.proto.v0 import anomalies_pb2
label_desc: Use image node_id 2 for calling a global function with example usage: remove_anomaly_types(anomalies, types_to_remove) without return types