code: def test_filter_metrics(self):
      eval_result = tfma.EvalResult(  # pytype: disable=wrong-arg-types
          slicing_metrics=_SLICING_METRICS,
          plots=None,
          attributions=None,
          config=None,
          data_location=None,
          file_format=None,
          model_location=None,
      )
      metrics_include = ["average_loss"]
      metrics_exclude = [
          "prediction/mean",
          "int_array",
          "float_array",
          "invalid_array",
      ]
      expected_slicing_metrics = [
          (
              (("weekday", 0),),
              {
                  "": {
                      "": {
                          "average_loss": {
                              "doubleValue": 0.07875693589448929
                          }
                      }
                  }
              },
          ),
          (
              (("weekday", 1),),
              {
                  "": {
                      "": {
                          "average_loss": {
                              "doubleValue": 4.4887189865112305
                          }
                      }
                  }
              },
          ),
          (
              (("weekday", 2),),
              {
                  "": {
                      "": {
                          "average_loss": {
                              "doubleValue": 2.092138290405273
                          }
                      }
                  }
              },
          ),
          (
              (("gender", "male"), ("age", 10)),
              {
                  "": {
                      "": {
                          "average_loss": {
                              "doubleValue": 2.092138290405273
                          }
                      }
                  }
              },
          ),
          (
              (("gender", "female"), ("age", 20)),
              {
                  "": {
                      "": {
                          "average_loss": {
                              "doubleValue": 2.092138290405273
                          }
                      }
                  }
              },
          ),
          (
              (),
              {
                  "": {
                      "": {
                          "average_loss": {
                              "doubleValue": 1.092138290405273
                          }
                      }
                  }
              },
          ),
      ]
      with self.subTest(name="metrics_include"):
          self.assertEqual(
              tf_utils.filter_metrics(
                  eval_result, metrics_include=metrics_include
              ).slicing_metrics,
              expected_slicing_metrics,
          )
      with self.subTest(name="metrics_exclude"):
          self.assertEqual(
              tf_utils.filter_metrics(
                  eval_result, metrics_exclude=metrics_exclude
              ).slicing_metrics,
              expected_slicing_metrics,
          )
      with self.subTest(
          name="both metrics_include and metrics_exclude (invalid)"
      ):
          with self.assertRaises(ValueError):
              tf_utils.filter_metrics(
                  eval_result,
                  metrics_include=metrics_include,
                  metrics_exclude=metrics_exclude,
              )
      with self.subTest(
          name="neither metrics_include nor metrics_exclude (invalid)"
      ):
          with self.assertRaises(ValueError):
              tf_utils.filter_metrics(eval_result)
  
imports: import os
  import uuid
  import ml_metadata
  import tensorflow_model_analysis
  from absl.testing import absltest
  from ml_metadata.proto import metadata_store_pb2
  from model_card_toolkit.model_card import ModelCard, PerformanceMetric
  from model_card_toolkit.utils import tf_utils
  from model_card_toolkit.utils.testdata import tf_testdata_utils
label_desc: Use image node_id 23 for calling the TfUtilsTest obj's underlying member method code with example usage: obj.test_filter_metrics() without return types