code: def test_with_weights(self):
      batches = [
          pa.RecordBatch.from_arrays(
              [
                  pa.array([[1.0], [2.0]]),
                  pa.array(
                      [
                          [{"f1": [{"f2": [1, 2]}, {"f2": [0]}]}],
                          [{"f1": [{"f2": [3, 3]}]}],
                      ]
                  ),
              ],
              ["w", "c"],
          )
      ]
  
      expected_result = {
          types.FeaturePath(["c"]): text_format.Parse(
              """
            type: STRUCT
            struct_stats {
              common_stats {
                num_non_missing: 2
                min_num_values: 1
                max_num_values: 1
                avg_num_values: 1.0
                num_values_histogram {
                  buckets {
                    low_value: 1.0
                    high_value: 1.0
                    sample_count: 1.0
                  }
                  buckets {
                    low_value: 1.0
                    high_value: 1.0
                    sample_count: 1.0
                  }
                  type: QUANTILES
                }
                weighted_common_stats {
                  num_non_missing: 3.0
                  avg_num_values: 1.0
                  tot_num_values: 3.0
                }
                tot_num_values: 2
              }
            }
            path {
              step: "c"
            }""",
              statistics_pb2.FeatureNameStatistics(),
          ),
          types.FeaturePath(["c", "f1"]): text_format.Parse(
              """
            type: STRUCT
            struct_stats {
              common_stats {
                num_non_missing: 2
                min_num_values: 1
                max_num_values: 2
                avg_num_values: 1.5
                num_values_histogram {
                  buckets {
                    low_value: 1.0
                    high_value: 2.0
                    sample_count: 1.5
                  }
                  buckets {
                    low_value: 2.0
                    high_value: 2.0
                    sample_count: 0.5
                  }
                  type: QUANTILES
                }
                weighted_common_stats {
                  num_non_missing: 3.0
                  avg_num_values: 1.3333333
                  tot_num_values: 4.0
                }
                tot_num_values: 3
              }
            }
            path {
              step: "c"
              step: "f1"
            }""",
              statistics_pb2.FeatureNameStatistics(),
          ),
          types.FeaturePath(["c", "f1", "f2"]): text_format.Parse(
              """
            num_stats {
              common_stats {
                num_non_missing: 3
                min_num_values: 1
                max_num_values: 2
                avg_num_values: 1.666667
                num_values_histogram {
                  buckets {
                    low_value: 1.0
                    high_value: 2.0
                    sample_count: 2.0
                  }
                  buckets {
                    low_value: 2.0
                    high_value: 2.0
                    sample_count: 1.0
                  }
                  type: QUANTILES
                }
                weighted_common_stats {
                  num_non_missing: 4.0
                  avg_num_values: 1.75
                  tot_num_values: 7.0
                }
                tot_num_values: 5
              }
              mean: 1.8
              std_dev: 1.1661904
              num_zeros: 1
              median: 2.0
              max: 3.0
              histograms {
                buckets {
                  high_value: 1.0
                  sample_count: 2.0
                }
                buckets {
                  low_value: 1.0
                  high_value: 2.0
                  sample_count: 1.0
                }
                buckets {
                  low_value: 2.0
                  high_value: 3.0
                  sample_count: 2.0
                }
              }
              histograms {
                buckets {
                  high_value: 1.0
                  sample_count: 2.0
                }
                buckets {
                  low_value: 1.0
                  high_value: 2.0
                  sample_count: 1.0
                }
                buckets {
                  low_value: 2.0
                  high_value: 3.0
                  sample_count: 1.0
                }
                buckets {
                  low_value: 3.0
                  high_value: 3.0
                  sample_count: 1.0
                }
                type: QUANTILES
              }
              weighted_numeric_stats {
                mean: 2.1428571
                std_dev: 1.1248583
                median: 3.0
                histograms {
                  buckets {
                    high_value: 1.0
                    sample_count: 2.0
                  }
                  buckets {
                    low_value: 1.0
                    high_value: 2.0
                    sample_count: 1.0
                  }
                  buckets {
                    low_value: 2.0
                    high_value: 3.0
                    sample_count: 4.0
                  }
                }
                histograms {
                  buckets {
                    high_value: 1.0
                    sample_count: 2.0
                  }
                  buckets {
                    low_value: 1.0
                    high_value: 3.0
                    sample_count: 1.6666667
                  }
                  buckets {
                    low_value: 3.0
                    high_value: 3.0
                    sample_count: 1.6666667
                  }
                  buckets {
                    low_value: 3.0
                    high_value: 3.0
                    sample_count: 1.6666667
                  }
                  type: QUANTILES
                }
              }
            }
            path {
              step: "c"
              step: "f1"
              step: "f2"
            }""",
              statistics_pb2.FeatureNameStatistics(),
          ),
          types.FeaturePath(["w"]): text_format.Parse(
              """
            type: FLOAT
            num_stats {
              common_stats {
                num_non_missing: 2
                min_num_values: 1
                max_num_values: 1
                avg_num_values: 1.0
                num_values_histogram {
                  buckets {
                    low_value: 1.0
                    high_value: 1.0
                    sample_count: 1.0
                  }
                  buckets {
                    low_value: 1.0
                    high_value: 1.0
                    sample_count: 1.0
                  }
                  type: QUANTILES
                }
                weighted_common_stats {
                  num_non_missing: 3.0
                  avg_num_values: 1.0
                  tot_num_values: 3.0
                }
                tot_num_values: 2
              }
              mean: 1.5
              std_dev: 0.5
              min: 1.0
              median: 2.0
              max: 2.0
              histograms {
                buckets {
                  low_value: 1.0
                  high_value: 1.33333333333
                  sample_count: 1.0016584
                }
                buckets {
                  low_value: 1.33333333333
                  high_value: 1.66666666667
                  sample_count: 0.0016584
                }
                buckets {
                  low_value: 1.66666666667
                  high_value: 2.0
                  sample_count: 0.9966833
                }
              }
              histograms {
                buckets {
                  low_value: 1.0
                  high_value: 1.0
                  sample_count: 1.0
                }
                buckets {
                  low_value: 1.0
                  high_value: 2.0
                  sample_count: 0.3333333
                }
                buckets {
                  low_value: 2.0
                  high_value: 2.0
                  sample_count: 0.3333333
                }
                buckets {
                  low_value: 2.0
                  high_value: 2.0
                  sample_count: 0.3333333
                }
                type: QUANTILES
              }
              weighted_numeric_stats {
                mean: 1.66666666667
                std_dev: 0.471404520791
                median: 2.0
                histograms {
                  buckets {
                    low_value: 1.0
                    high_value: 1.33333333333
                    sample_count: 1.0024969
                  }
                  buckets {
                    low_value: 1.33333333333
                    high_value: 1.66666666667
                    sample_count: 0.0024969
                  }
                  buckets {
                    low_value: 1.66666666667
                    high_value: 2.0
                    sample_count: 1.9950062
                  }
                }
                histograms {
                  buckets {
                    low_value: 1.0
                    high_value: 1.0
                    sample_count: 1.0
                  }
                  buckets {
                    low_value: 1.0
                    high_value: 2.0
                    sample_count: 0.6666667
                  }
                  buckets {
                    low_value: 2.0
                    high_value: 2.0
                    sample_count: 0.6666667
                  }
                  buckets {
                    low_value: 2.0
                    high_value: 2.0
                    sample_count: 0.6666667
                  }
                  type: QUANTILES
                }
              }
            }
        path {
          step: "w"
        }
      """,
              statistics_pb2.FeatureNameStatistics(),
          ),
      }
      generator = basic_stats_generator.BasicStatsGenerator(
          example_weight_map=ExampleWeightMap(weight_feature="w"),
          num_values_histogram_buckets=2,
          num_histogram_buckets=3,
          num_quantiles_histogram_buckets=4,
      )
      self.assertCombinerOutputEqual(
          batches, generator, expected_result
      )
  
imports: from absl.testing import absltest
  from absl.testing import parameterized
  import numpy
  import pyarrow
  from tensorflow_data_validation import types
  from tensorflow_data_validation.statistics.generators import basic_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 2 for calling the BasicStatsGeneratorStructStatsTest obj's underlying member method code with example usage: obj.test_with_weights() without return types