code: def _strip_infinities(
      quantiles: np.ndarray,
      cumulative_counts: np.ndarray,
      finite_max: float,
      num_pos_inf: float,
  ) -> Tuple[np.ndarray, np.ndarray, float]:
      """Removes buckets containing infinite bounds.
  
      Args:
        quantiles: A numpy array containing the quantile boundaries.
        cumulative_counts: A numpy array of the same length as quantiles containing
          the cumulative quantile counts (or cumsum of weights).
        finite_max: The maximum finite value.
        num_pos_inf: The total count of positive infinite values. May be non-
          integral if weighted.
  
      Returns:
        A tuple consisting of new quantiles, new cumulative counts, and the total
        count of removed buckets ending in negative infinity.
  
      """
      # Find the largest index containing a -inf bucket upper bound.
      neg_inf_idx = np.searchsorted(
          quantiles, float("-inf"), side="right"
      )
      # First we strip negative infinities. Because quantiles represents bucket
      # right hand bounds, we can just chop off any buckets with a value of -inf.
      if neg_inf_idx:
          # Strip off negative infinities.
          # Note that the quantiles will be off by num_neg_inf, because they only
          # count finite values.
          num_neg_inf = cumulative_counts[neg_inf_idx - 1]
          cumulative_counts = cumulative_counts[neg_inf_idx:]
          quantiles = quantiles[neg_inf_idx:]
          cumulative_counts = cumulative_counts - num_neg_inf
      else:
          num_neg_inf = 0
      # Now we strip positive infinities. A bucket with a right hand bound of +inf
      # may contain some finite values, so we need to use a separately computed
      # number of positive inf values.
      if num_pos_inf:
          pos_inf_index = np.searchsorted(
              quantiles, float("inf"), side="left"
          )
          # Subtract num_pos_inf from the total count to get the total count of finite
          # elements.
          finite_max_count = cumulative_counts[-1] - num_pos_inf
  
          # Strip off +inf
          quantiles = quantiles[:pos_inf_index]
          cumulative_counts = cumulative_counts[:pos_inf_index]
  
          # If a trailing bucket contained the finite max, concatenate a new bucket
          # ending in that value.
          quantiles = np.concatenate(
              [quantiles, np.array([finite_max])]
          )
          cumulative_counts = np.concatenate(
              [cumulative_counts, np.array([finite_max_count])]
          )
      return quantiles, cumulative_counts, num_neg_inf
  
file_path: data-validation/tensorflow_data_validation/utils/quantiles_util.py
imports: from typing import Tuple
  import numpy
  from tensorflow_metadata.proto.v0 import statistics_pb2
label_desc: Use image node_id 5 for calling a global function with example usage: _strip_infinities(quantiles, cumulative_counts, finite_max, num_pos_inf) and returns: quantiles,  cumulative_counts,  num_neg_inf