class_docstr: Tests for LiftStatsGenerator.
class_docstr_tok: ["Tests","for","LiftStatsGenerator","."]
code: def test_lift_int_y(self):
      examples = [
          pa.RecordBatch.from_arrays(
              [
                  pa.array([["a"], ["a"], ["b"], ["a"]]),
                  pa.array([[1], [0], [1], [0]]),
              ],
              ["categorical_x", "int_y"],
          ),
      ]
      schema = text_format.Parse(
          """
          feature {
            name: 'categorical_x'
            type: BYTES
          }
          feature {
            name: 'int_y'
            type: INT
            int_domain {
              is_categorical: true
            }
          }
          """,
          schema_pb2.Schema(),
      )
      expected_result = [
          text_format.Parse(
              """
              features {
                custom_stats {
                  name: "Lift (Y=0)"
                  rank_histogram {
                    buckets {
                      label: "a"
                      sample_count: 1.3333333
                    }
                    buckets {
                      label: "b"
                    }
                  }
                }
                custom_stats {
                  name: "Lift (Y=1)"
                  rank_histogram {
                    buckets {
                      label: "b"
                      sample_count: 2.0
                    }
                    buckets {
                      label: "a"
                      sample_count: 0.6666667
                    }
                  }
                }
                path {
                  step: "categorical_x"
                }
              }
              cross_features {
                path_x {
                  step: "categorical_x"
                }
                path_y {
                  step: "int_y"
                }
                categorical_cross_stats {
                  lift {
                    lift_series {
                      y_int: 0
                      y_count: 2
                      lift_values {
                        x_string: "a"
                        lift: 1.3333333
                        x_count: 3
                        x_and_y_count: 2
                      }
                      lift_values {
                        x_string: "b"
                        lift: 0.0
                        x_count: 1
                        x_and_y_count: 0
                      }
                    }
                    lift_series {
                      y_int: 1
                      y_count: 2
                      lift_values {
                        x_string: "b"
                        lift: 2.0
                        x_count: 1
                        x_and_y_count: 1
                      }
                      lift_values {
                        x_string: "a"
                        lift: 0.6666667
                        x_count: 3
                        x_and_y_count: 1
                      }
                    }
                  }
                }
              }""",
              statistics_pb2.DatasetFeatureStatistics(),
          ),
      ]
  
      def metrics_verify_fn(metric_results):
          num_xy_pairs_distinct_counters = metric_results.query(
              beam.metrics.metric.MetricsFilter().with_name(
                  "num_xy_pairs_distinct"
              )
          )[beam.metrics.metric.MetricResults.COUNTERS]
          self.assertLen(num_xy_pairs_distinct_counters, 1)
          self.assertEqual(
              4, num_xy_pairs_distinct_counters[0].committed
          )
  
          num_xy_pairs_batch_copresent_dists = metric_results.query(
              beam.metrics.metric.MetricsFilter().with_name(
                  "num_xy_pairs_batch_copresent"
              )
          )[beam.metrics.metric.MetricResults.DISTRIBUTIONS]
          self.assertLen(num_xy_pairs_batch_copresent_dists, 1)
          num_xy_pairs_batch_copresent_dist = (
              num_xy_pairs_batch_copresent_dists[0]
          )
          self.assertEqual(
              3, num_xy_pairs_batch_copresent_dist.committed.sum
          )
          self.assertEqual(
              1, num_xy_pairs_batch_copresent_dist.committed.count
          )
          self.assertEqual(
              3, num_xy_pairs_batch_copresent_dist.committed.min
          )
          self.assertEqual(
              3, num_xy_pairs_batch_copresent_dist.committed.max
          )
  
          placeholder_num_right_keys_dists = metric_results.query(
              beam.metrics.metric.MetricsFilter()
              .with_name("right_lookup_num_keys")
              .with_step("JoinWithPlaceholderYRates")
          )[beam.metrics.metric.MetricResults.DISTRIBUTIONS]
          self.assertLen(placeholder_num_right_keys_dists, 1)
          placeholder_num_right_keys_dist = (
              placeholder_num_right_keys_dists[0]
          )
          # min and max should always equal because this dist is really a gauge
          # The expected number of distinct keys is the number of slices, as the
          # lookup is built from a stream of slice_key / y-value pairs.
          self.assertEqual(
              1, placeholder_num_right_keys_dist.committed.min
          )
          self.assertEqual(
              1, placeholder_num_right_keys_dist.committed.max
          )
  
          placeholder_num_right_values_dists = metric_results.query(
              beam.metrics.metric.MetricsFilter()
              .with_name("right_lookup_num_values")
              .with_step("JoinWithPlaceholderYRates")
          )[beam.metrics.metric.MetricResults.DISTRIBUTIONS]
          self.assertLen(placeholder_num_right_values_dists, 1)
          placeholder_num_right_values_dist = (
              placeholder_num_right_values_dists[0]
          )
          # min and max should always equal because this dist is really a gauge
          # The expected number of values is the total number of y-values across
          # all slices, as the lookup is built from a stream of slice_key / y-value
          # pairs.
          self.assertEqual(
              2, placeholder_num_right_values_dist.committed.min
          )
          self.assertEqual(
              2, placeholder_num_right_values_dist.committed.max
          )
  
          placeholder_construction_dists = metric_results.query(
              beam.metrics.metric.MetricsFilter()
              .with_name("right_lookup_construction_seconds")
              .with_step("JoinWithPlaceholderYRates")
          )[beam.metrics.metric.MetricResults.DISTRIBUTIONS]
          self.assertLen(placeholder_construction_dists, 1)
          placeholder_construction_dist = (
              placeholder_construction_dists[0]
          )
          self.assertGreater(
              placeholder_construction_dist.committed.count, 0
          )
  
      generator = lift_stats_generator.LiftStatsGenerator(
          schema=schema,
          y_path=types.FeaturePath(["int_y"]),
          output_custom_stats=True,
      )
      self.assertSlicingAwareTransformOutputEqual(
          examples,
          generator,
          expected_result,
          metrics_verify_fn=metrics_verify_fn,
          add_default_slice_key_to_input=True,
          add_default_slice_key_to_output=True,
      )
  
imports: from typing import Optional, Sequence, Text
  from absl.testing import absltest
  import apache_beam
  import numpy
  import pandas
  import pyarrow
  from tensorflow_data_validation import types
  from tensorflow_data_validation.statistics.generators import lift_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 6 for calling the LiftStatsGeneratorTest obj's underlying member method code with example usage: obj.test_lift_int_y() without return types