code: def merge(prior, latest):
      
      if not _buckets_nearly_equal(prior, latest):
          _logger.error(u'Bucket options do not match. From %s To: %s',
                        prior,
                        latest)
          raise ValueError(u'Bucket options do not match')
      if len(prior.bucketCounts) != len(latest.bucketCounts):
          _logger.error(u'Bucket count sizes do not match. From %s To: %s',
                        prior,
                        latest)
          raise ValueError(u'Bucket count sizes do not match')
      if prior.count <= 0:
          return
  
      old_count = latest.count
      old_mean = latest.mean
      old_summed_variance = latest.sumOfSquaredDeviation
      bucket_counts = latest.bucketCounts
  
      # Update the latest
      latest.count += prior.count
      latest.maximum = max(prior.maximum, latest.maximum)
      latest.minimum = min(prior.minimum, latest.minimum)
      latest.mean = ((old_count * old_mean + prior.count * prior.mean) /
                     latest.count)
      latest.sumOfSquaredDeviation = (
          old_summed_variance + prior.sumOfSquaredDeviation +
          old_count * (latest.mean - old_mean) ** 2 +
          prior.count * (latest.mean - prior.mean) ** 2)
      for i, (x, y) in enumerate(zip(prior.bucketCounts, bucket_counts)):
          bucket_counts[i] = x + y
docs: Merge `prior` into `latest`.
  
      N.B, this mutates latest. It ensures that the statistics and histogram are
      updated to correctly include the original values from both instances.
  
      Args:
        prior (:class:`endpoints_management.gen.servicecontrol_v1_messages.Distribution`):
          an instance
        latest (:class:`endpoints_management.gen.servicecontrol_v1_messages.Distribution`):
          an instance to be updated
  
      Raises:
        ValueError: if the bucket options of `prior` and `latest` do not match
        ValueError: if the bucket counts of `prior` and `latest` do not match