class_docstr: Specification for a single slice.
  
  This is intended to be an immutable class that specifies a single slice.
  Use this in conjunction with get_slices_for_features_dicts to generate slices
  for dictionaries of features.
  
  Examples:
    - columns = ['age'], features = []
      This means to slice by the 'age' column.
    - columns = ['age'], features = [('gender', 'female')]
      This means to slice by the 'age' column if the 'gender' is 'female'.
    - For more examples, refer to the tests in slicer_test.py.
class_docstr_tok: ["Specification","for","a","single","slice",".","This","is","intended","to","be","an","immutable","class","that","specifies","a","single","slice",".","Use","this","in","conjunction","with","get_slices_for_features_dicts","to","generate","slices","for","dictionaries","of","features",".","Examples",":","-","columns","=","[","'age","'","]",",","features","=","[","]","This","means","to","slice","by","the","'age","'","column",".","-","columns","=","[","'age","'","]",",","features","=","[","(","'gender","'",",","'female","'",")","]","This","means","to","slice","by","the","'age","'","column","if","the","'gender","'","is","'female","'",".","-","For","more","examples",",","refer","to","the","tests","in","slicer_test.py","."]
docstr: Generates all slices that match this specification from the data.
  
  Should only be called within this file.
  
  Examples:
    - columns = [], features = [] (the overall slice case)
      slice accessor has features age=[5], gender=['f'], interest=['knitting']
      returns [()]
    - columns = ['age'], features = [('gender', 'f')]
      slice accessor has features age=[5], gender=['f'], interest=['knitting']
      returns [[('age', 5), ('gender, 'f')]]
    - columns = ['interest'], features = [('gender', 'f')]
      slice accessor has features age=[5], gender=['f'],
      interest=['knitting', 'games']
      returns [[('gender', 'f'), ('interest, 'knitting')],
               [('gender', 'f'), ('interest, 'games')]]
  
  Args:
    accessor: slice accessor.
  
  Yields:
    A SliceKeyType for each slice that matches this specification. Nothing
    will be yielded if there no slices matched this specification. The entries
    in the yielded SliceKeyTypes are guaranteed to be sorted by key names (and
    then values, if necessary), ascending.
code: def generate_slices(
      self, accessor: slice_accessor.SliceAccessor
  ) -> Generator[SliceKeyType, None, None]:
      """Generates all slices that match this specification from the data.
  
      Should only be called within this file.
  
      Examples:
        - columns = [], features = [] (the overall slice case)
          slice accessor has features age=[5], gender=['f'], interest=['knitting']
          returns [()]
        - columns = ['age'], features = [('gender', 'f')]
          slice accessor has features age=[5], gender=['f'], interest=['knitting']
          returns [[('age', 5), ('gender, 'f')]]
        - columns = ['interest'], features = [('gender', 'f')]
          slice accessor has features age=[5], gender=['f'],
          interest=['knitting', 'games']
          returns [[('gender', 'f'), ('interest, 'knitting')],
                   [('gender', 'f'), ('interest, 'games')]]
  
      Args:
        accessor: slice accessor.
  
      Yields:
        A SliceKeyType for each slice that matches this specification. Nothing
        will be yielded if there no slices matched this specification. The entries
        in the yielded SliceKeyTypes are guaranteed to be sorted by key names (and
        then values, if necessary), ascending.
      """
      # Check all the value matches (where there's a specific value specified).
      for key, value in self._features:
          if not accessor.has_key(key):
              return
  
          accessor_values = accessor.get(key)
          if value not in accessor_values:
              if isinstance(value, str):
                  if (
                      value.encode() not in accessor_values
                  ):  # For Python3.
                      return
              # Check that string version of int/float not in values.
              elif str(value) not in accessor_values:
                  return
  
      # Get all the column matches (where we're matching only the column).
      #
      # For each column, we generate a List[SingletonSliceKeyType] containing
      # all pairs (column, value) for all values of the column. So this will be
      # a List[List[SingletonSliceKeyType]].
      #
      # For example, column_matches might be:
      # [[('gender', 'f'), ('gender', 'm')], [('age', 4), ('age', 5)]]
      column_matches = []
      for column in self._columns:
          # If a column to slice on doesn't appear in the example, then there will
          # be no applicable slices, so return.
          if not accessor.has_key(column):
              return
  
          column_match = []
          for value in accessor.get(column):
              if isinstance(value, bytes):
                  try:
                      column_match.append(
                          (column, tf.compat.as_text(value))
                      )
                  except UnicodeDecodeError as e:
                      raise ValueError(
                          "Found non-UTF8 feature value {} in "
                          'column "{}"'.format(value, column)
                      ) from e
              else:
                  column_match.append((column, value))
          column_matches.append(column_match)
  
      # We can now take the Cartesian product of the column_matches, and append
      # the value matches to each element of that, to generate the final list of
      # slices. Note that for the overall slice case the column_matches is [] and
      # the Cartesian product of [] is ().
      for column_part in itertools.product(*column_matches):
          yield tuple(sorted(self._value_matches + list(column_part)))
  
imports: import itertools
  from typing import Any, Callable, Dict, Generator, Iterable, List, NamedTuple, Optional, Tuple, Union
  import apache_beam
  import numpy
  import tensorflow
  from tensorflow_model_analysis import constants
  from tensorflow_model_analysis.api import types
  from tensorflow_model_analysis.proto import config_pb2
  from tensorflow_model_analysis.proto import metrics_for_slice_pb2
  from tensorflow_model_analysis.slicer import slice_accessor
label_desc: Use image node_id 9 for calling the SingleSliceSpec obj's underlying member method code with example usage: obj.generate_slices(accessor) without return types