class_docstr: Tests for TopKUniquesSketchStatsGenerator.
class_docstr_tok: ["Tests","for","TopKUniquesSketchStatsGenerator","."]
code: def test_topk_struct_leaves(self):
      batches = [
          pa.RecordBatch.from_arrays(
              [
                  pa.array([[1.0], [2.0]]),
                  pa.array(
                      [
                          [
                              {"f1": ["a", "b"], "f2": [1, 2]},
                              {
                                  "f1": ["b"],
                              },
                          ],
                          [
                              {"f1": ["c", "d"], "f2": [2, 3]},
                              {"f2": [3]},
                          ],
                      ]
                  ),
              ],
              ["w", "c"],
          ),
          pa.RecordBatch.from_arrays(
              [
                  pa.array([[3.0]]),
                  pa.array([[{"f1": ["d"], "f2": [4]}]]),
              ],
              ["w", "c"],
          ),
      ]
      schema = text_format.Parse(
          """
          feature {
            name: "c"
            type: STRUCT
            struct_domain {
              feature {
                name: "f2"
                type: INT
                int_domain {
                  is_categorical: true
                }
              }
            }
          }
          """,
          schema_pb2.Schema(),
      )
      expected_result = {
          types.FeaturePath(["c", "f1"]): text_format.Parse(
              """
                string_stats {
                  unique: 4
                  top_values {
                    value: "d"
                    frequency: 2.0
                  }
                  top_values {
                    value: "b"
                    frequency: 2.0
                  }
                  top_values {
                    value: "c"
                    frequency: 1.0
                  }
                  rank_histogram {
                    buckets {
                      label: "d"
                      sample_count: 2.0
                    }
                    buckets {
                      low_rank: 1
                      high_rank: 1
                      label: "b"
                      sample_count: 2.0
                    }
                    buckets {
                      low_rank: 2
                      high_rank: 2
                      label: "c"
                      sample_count: 1.0
                    }
                  }
                  weighted_string_stats {
                    top_values {
                      value: "d"
                      frequency: 5.0
                    }
                    top_values {
                      value: "c"
                      frequency: 2.0
                    }
                    top_values {
                      value: "b"
                      frequency: 2.0
                    }
                    rank_histogram {
                      buckets {
                        label: "d"
                        sample_count: 5.0
                      }
                      buckets {
                        low_rank: 1
                        high_rank: 1
                        label: "c"
                        sample_count: 2.0
                      }
                      buckets {
                        low_rank: 2
                        high_rank: 2
                        label: "b"
                        sample_count: 2.0
                      }
                    }
                  }
                }
                path {
                  step: "c"
                  step: "f1"
                }""",
              statistics_pb2.FeatureNameStatistics(),
          ),
          types.FeaturePath(["c", "f2"]): text_format.Parse(
              """
                string_stats {
                  unique: 4
                  top_values {
                    value: "3"
                    frequency: 2.0
                  }
                  top_values {
                    value: "2"
                    frequency: 2.0
                  }
                  top_values {
                    value: "4"
                    frequency: 1.0
                  }
                  rank_histogram {
                    buckets {
                      label: "3"
                      sample_count: 2.0
                    }
                    buckets {
                      low_rank: 1
                      high_rank: 1
                      label: "2"
                      sample_count: 2.0
                    }
                    buckets {
                      low_rank: 2
                      high_rank: 2
                      label: "4"
                      sample_count: 1.0
                    }
                  }
                  weighted_string_stats {
                    top_values {
                      value: "3"
                      frequency: 4.0
                    }
                    top_values {
                      value: "4"
                      frequency: 3.0
                    }
                    top_values {
                      value: "2"
                      frequency: 3.0
                    }
                    rank_histogram {
                      buckets {
                        label: "3"
                        sample_count: 4.0
                      }
                      buckets {
                        low_rank: 1
                        high_rank: 1
                        label: "4"
                        sample_count: 3.0
                      }
                      buckets {
                        low_rank: 2
                        high_rank: 2
                        label: "2"
                        sample_count: 3.0
                      }
                    }
                  }
                }
                path {
                  step: "c"
                  step: "f2"
                }""",
              statistics_pb2.FeatureNameStatistics(),
          ),
      }
      generator = sketch_generator.TopKUniquesSketchStatsGenerator(
          schema=schema,
          example_weight_map=ExampleWeightMap(weight_feature="w"),
          num_top_values=3,
          num_rank_histogram_buckets=3,
      )
  
      self.assertCombinerOutputEqual(
          batches, generator, expected_result
      )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from absl.testing import absltest
  from absl.testing import parameterized
  import pyarrow
  from tensorflow_data_validation import types
  from tensorflow_data_validation.statistics.generators import top_k_uniques_sketch_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 11 for calling the TopKUniquesSketchStatsGeneratorTest obj's underlying member method code with example usage: obj.test_topk_struct_leaves() without return types