code: def regularize_series(
      series,
      frequency=None,
      warn_missing_tolerance=None,
      err_missing_tolerance=None,
      max_series_length=None,
  ):
      """Infers frequency and makes an irregular time series regular.
  
      Converts a time series into a regular time series having the same
      period between successive time points (e.g. 5 seconds, or 1 day).  If
      the frequency is known, it can be supplied through the 'frequency'
      argument; otherwise it will be inferred.
  
      If multiple values share the same timestamp, they are summed into a single
      value.
  
      Args:
        series: a Pandas `pd.Series` instance indexed by a `pd.DateTimeIndex`. This
          may also be a single-column `pd.DataFrame`.
        frequency: a Pandas DateOffset object, e.g. `pd.DateOffset(seconds=1)`. If
          no frequency is specified, and the index of `series` does not have a
          frequency populated, the granularity of the time series will be inferred
          automatically.
          Default value: `None`.
        warn_missing_tolerance: optional instance of
          `tfp.sts.MissingValuesTolerance`, specifying warning thresholds for
          too many missing values.
          Default value: `None`. (do not warn).
        err_missing_tolerance: optional instance of
          `tfp.sts.MissingValuesTolerance`, specifying error thresholds for
          too many missing values.
          Default value: `None`. (do not raise errors).
        max_series_length: `int` maximum length of the regularized
          series (note that regularization may increase the length of the series).
          Used to bound the resources used per invocation.
          Default value: `None`.
      Returns:
        regularized_series: instance of the same type as `series`
          (`pd.Series` or `pd.DataFrame`) whose index follows a regular
          frequency (`regularized_series.index.freq is not None`). Any values
          not provided are filled in as `NaN`.
      Raises:
        TypeError: if `data` is not an instance of `pd.Series` or `pd.DataFrame`.
        ValueError:  if `data` is empty, `data.index` is not a DatetimeIndex,
                     `data.index` is not sorted, or if applying the inferred
                     frequency would exceed the `max_series_length` or create
                     more missing values than allowed by `err_missing_vals`.
      """
      # pylint: disable=unused-import,g-import-not-at-top
      import pandas as pd  # Defer import to avoid a package-level Pandas dep.
      from pandas.core.resample import asfreq  # see b/169217869
  
      # pylint: enable=unused-import,g-import-not-at-top
  
      _check_data(series)
  
      # Sum all values provided at each time step, if there is more than one.
      series = series.groupby(
          by=lambda x: x
          # Use numpy sum because just calling `groupby().sum()` would drop NaNs.
      ).agg(lambda x: np.sum(x.values))
  
      if not frequency:
          frequency = _infer_frequency(series.index)
  
      # If the frequency is monthly and the first date is the end of a
      # month, follow that convention in future months. Note that this condition
      # is not triggered if the frequency is already `MonthEnd` (which has
      # `kwds == {}`).
      if (
          "months" in frequency.kwds
          and len(frequency.kwds) == 1
          and np.all(series.index.is_month_end)
      ):
          frequency = pd.offsets.MonthEnd(n=frequency.kwds["months"])
  
      if (
          max_series_length is not None
          and max_series_length
          < _estimate_num_steps(
              series.index[0], series.index[-1], frequency
          )
      ):
          raise ValueError(
              "Applying inferred frequency {} to the time period "
              "starting at '{}' and ending at '{}' would exceed the "
              "maximum series length ({}).".format(
                  frequency,
                  series.index[0],
                  series.index[-1],
                  max_series_length,
              )
          )
  
      regularized_series = series.asfreq(frequency)
      if warn_missing_tolerance or err_missing_tolerance:
          _check_missing_values(
              regularized_series,
              warn_vals=warn_missing_tolerance,
              err_vals=err_missing_tolerance,
          )
      return regularized_series
  
file_path: probability/tensorflow_probability/python/sts/regularization.py
imports: import collections
  import itertools
  import math
  import warnings
  import numpy
label_desc: Use image node_id 1 for calling a global function with example usage: regularize_series(series, frequency, warn_missing_tolerance, err_missing_tolerance, max_series_length) and returns: regularized_series