class_docstr: Tests for TopkUniquesStatsGenerator.
class_docstr_tok: ["Tests","for","TopkUniquesStatsGenerator","."]
code: def test_topk_uniques_with_slicing(self):
      examples = [
          (
              "slice1",
              pa.RecordBatch.from_arrays(
                  [
                      pa.array([["a", "b", "c", "e"]]),
                      pa.array([["1", "1", "0"]]),
                  ],
                  ["fa", "fb"],
              ),
          ),
          (
              "slice2",
              pa.RecordBatch.from_arrays(
                  [
                      pa.array([["b", "a", "e", "c"]]),
                      pa.array([["0", "0", "1"]]),
                  ],
                  ["fa", "fb"],
              ),
          ),
          (
              "slice1",
              pa.RecordBatch.from_arrays(
                  [pa.array([["a", "c", "d", "a"]])], ["fa"]
              ),
          ),
          (
              "slice2",
              pa.RecordBatch.from_arrays(
                  [pa.array([["b", "e", "d", "b"]])], ["fa"]
              ),
          ),
      ]
  
      # Note that if two feature values have the same frequency, the one with the
      # lexicographically larger feature value will be higher in the order.
      expected_result = [
          (
              "slice1",
              text_format.Parse(
                  """
        features {
          path {
            step: 'fa'
          }
          string_stats {
            top_values {
              value: 'a'
              frequency: 3
            }
            top_values {
              value: 'c'
              frequency: 2
            }
            rank_histogram {
              buckets {
                low_rank: 0
                high_rank: 0
                label: "a"
                sample_count: 3.0
              }
              buckets {
                low_rank: 1
                high_rank: 1
                label: "c"
                sample_count: 2.0
              }
            }
          }
        }
      """,
                  statistics_pb2.DatasetFeatureStatistics(),
              ),
          ),
          (
              "slice1",
              text_format.Parse(
                  """
        features {
          path {
            step: 'fb'
          }
          string_stats {
            top_values {
              value: '1'
              frequency: 2
            }
            top_values {
              value: '0'
              frequency: 1
            }
            rank_histogram {
              buckets {
                low_rank: 0
                high_rank: 0
                label: "1"
                sample_count: 2.0
              }
              buckets {
                low_rank: 1
                high_rank: 1
                label: "0"
                sample_count: 1.0
              }
            }
          }
        }
      """,
                  statistics_pb2.DatasetFeatureStatistics(),
              ),
          ),
          (
              "slice1",
              text_format.Parse(
                  """
        features {
          path {
            step: 'fa'
          }
          string_stats {
            unique: 5
          }
      }""",
                  statistics_pb2.DatasetFeatureStatistics(),
              ),
          ),
          (
              "slice1",
              text_format.Parse(
                  """
        features {
          path {
            step: 'fb'
          }
          string_stats {
            unique: 2
          }
      }""",
                  statistics_pb2.DatasetFeatureStatistics(),
              ),
          ),
          (
              "slice2",
              text_format.Parse(
                  """
        features {
          path {
            step: 'fa'
          }
          string_stats {
            top_values {
              value: 'b'
              frequency: 3
            }
            top_values {
              value: 'e'
              frequency: 2
            }
            rank_histogram {
              buckets {
                low_rank: 0
                high_rank: 0
                label: "b"
                sample_count: 3.0
              }
              buckets {
                low_rank: 1
                high_rank: 1
                label: "e"
                sample_count: 2.0
              }
            }
          }
        }
      """,
                  statistics_pb2.DatasetFeatureStatistics(),
              ),
          ),
          (
              "slice2",
              text_format.Parse(
                  """
        features {
          path {
            step: 'fb'
          }
          string_stats {
            top_values {
              value: '0'
              frequency: 2
            }
            top_values {
              value: '1'
              frequency: 1
            }
            rank_histogram {
              buckets {
                low_rank: 0
                high_rank: 0
                label: "0"
                sample_count: 2.0
              }
              buckets {
                low_rank: 1
                high_rank: 1
                label: "1"
                sample_count: 1.0
              }
            }
          }
        }
      """,
                  statistics_pb2.DatasetFeatureStatistics(),
              ),
          ),
          (
              "slice2",
              text_format.Parse(
                  """
        features {
          path {
            step: 'fa'
          }
          string_stats {
            unique: 5
          }
      }""",
                  statistics_pb2.DatasetFeatureStatistics(),
              ),
          ),
          (
              "slice2",
              text_format.Parse(
                  """
        features {
          path {
            step: 'fb'
          }
          string_stats {
            unique: 2
          }
      }""",
                  statistics_pb2.DatasetFeatureStatistics(),
              ),
          ),
      ]
  
      generator = (
          top_k_uniques_stats_generator.TopKUniquesStatsGenerator(
              num_top_values=2, num_rank_histogram_buckets=2
          )
      )
      self.assertSlicingAwareTransformOutputEqual(
          examples, generator, expected_result
      )
  
imports: from absl.testing import absltest
  import pyarrow
  from tensorflow_data_validation import types
  from tensorflow_data_validation.statistics.generators import top_k_uniques_stats_generator
  from tensorflow_data_validation.utils import test_util
  from tensorflow_data_validation.utils.example_weight_map import ExampleWeightMap
  from google.protobuf import text_format
  from tensorflow_metadata.proto.v0 import schema_pb2
  from tensorflow_metadata.proto.v0 import statistics_pb2
label_desc: Use image node_id 13 for calling the TopkUniquesStatsGeneratorTest obj's underlying member method code with example usage: obj.test_topk_uniques_with_slicing() without return types