def record_batch_to_instance_dicts(
    record_batch: pa.RecordBatch, schema: schema_pb2.Schema
) -> List[common_types.InstanceDictType]:
  """Converts pa.RecordBatch to list of Python dictionaries.

  Args:
    record_batch: the batch to be converted.
    schema: A `Schema` proto.

  Returns:
    A list of dicts where each dict is an in-memory representation of an
        instance.
  """
  # Alternatively, we could've used `record_batch.to_pylist()`, but
  # RaggedTensors would be represented as nested lists (as opposed to array of
  # values + row lengths), so we make a trip through flat examples first.
  coder = example_coder.RecordBatchToExamplesEncoder(schema)
  examples = coder.encode(record_batch)
  # Dense tensor instances must be reshaped according to their spec shape.
  # Scalars are represented as Python scalars (as opposed to singleton arrays).
  feature_spec = schema_utils.schema_as_feature_spec(schema).feature_spec
  dense_reshape_fns = {}
  def _extract_singleton_item(
      singleton: np.ndarray,
  ) -> common_types.PrimitiveType:
    return singleton.item()
  for name, spec in feature_spec.items():
    if isinstance(spec, tf.io.FixedLenFeature):
      if spec.shape:
        dense_reshape_fns[name] = functools.partial(
            np.reshape, newshape=spec.shape
        )
      else:
        dense_reshape_fns[name] = _extract_singleton_item
  result = []
  for example in examples:
    instance_dict = _example_to_dict(example)
    for name, reshape_fn in dense_reshape_fns.items():
      instance_dict[name] = reshape_fn(instance_dict[name])
    result.append(instance_dict)
  return result
Converts pa.RecordBatch to list of Python dictionaries.

  Args:
    record_batch: the batch to be converted.
    schema: A `Schema` proto.

  Returns:
    A list of dicts where each dict is an in-memory representation of an
        instance.
  
tensorflow_transform/impl_helper.py