code: def _infer_frequency(date_time_index):
      """Infers frequency from a Pandas DatetimeIndex.
  
      The frequency is automatically inferred as follows:
          1. Computes the time differences between all time points and determine
             the smallest difference.
          2. For the smallest time difference determine the smallest time
             component from 'seconds', 'minutes, 'hours', 'days', and 'weeks'.
          3. Convert all time differences to the smallest time component determined
             in (2).
          4. Find the greatest common denominator (gcd) determined from the
             resulting time differences in (3). This is used to automatically
             set a time series frequency.
  
      Args:
        date_time_index: instance of Pandas.DatetimeIndex. Typically this is
          `df.index` for an appropriate dateframe `df`.
      Returns:
        frequency: The inferred frequency as a `pd.DateOffset` instance. This will
          either be a special offset, like `pd.offsets.MonthEnd()`, or will be a
          base `pd.DateOffset` instance with a single keyword component
          (e.g., `DateOffset(hours=26)` rather than `DateOffset(days=1, hours=2)`).
      """
      # Defer import to avoid a package-level Pandas dep.
      import pandas as pd  # pylint: disable=g-import-not-at-top
  
      # Compute series time deltas and get their minimum.
      diffs = pd.Series(date_time_index).diff()[1:]
      diffs_table = diffs.value_counts()
      min_diff = diffs_table.index.min()
  
      # Extract datetime components and identify smallest time component.
      min_diff_components = pd.Series(min_diff).dt.components
      available_components = list(min_diff_components)
      components_present = min_diff_components.values[0] > 0
      smallest_unit = list(
          itertools.compress(available_components, components_present)
      )[-1]
  
      irregular_freqs = []
      if smallest_unit == "days" and min_diff.days >= 365:
          # Attempt to infer a yearly frequency.
          irregular_freqs += [pd.DateOffset(years=min_diff.days // 365)]
      if smallest_unit == "days" and min_diff.days >= 28:
          # Attempt to infer a monthly frequency. Note that the candidate interval of
          # `days // 28` will fail for intervals larger than 11 months.
          irregular_freqs += [
              pd.DateOffset(months=min_diff.days // 28),
              pd.offsets.MonthEnd(n=min_diff.days // 28),
          ]
      for candidate_freq in irregular_freqs:
          # If the candidate frequency explains all of the provided dates, it's
          # probably a reasonable choice.
          if set(
              pd.date_range(
                  date_time_index.min(),
                  date_time_index.max(),
                  freq=candidate_freq,
              )
          ).issuperset(date_time_index):
              return candidate_freq
  
      # Pandas Timedelta does not support 'weeks' time components by default.
      # Deal with that special case.
      if smallest_unit == "days" and min_diff.days % 7 == 0:
          smallest_unit = "weeks"
  
      # Express time differences in common unit
      series_divider = np.timedelta64(
          1, _PD_TO_NP_DELTAS[smallest_unit]
      )
      diffs_common = list((diffs / series_divider).astype(int))
  
      # Compute the greatest common denominator of time differences.
      diffs_gcd = diffs_common[0]
      for d in diffs_common[1:]:
          diffs_gcd = math.gcd(diffs_gcd, d)
  
      return pd.DateOffset(**{smallest_unit: diffs_gcd})
  
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 4 for calling a global function with example usage: _infer_frequency(date_time_index) and returns: pd, candidate_freq