def _estimate_num_steps(start_time, end_time, freq):
  """Estimates the number of steps between the given times at the given freq."""
  # Unfortunately `(end_time - start_time) / freq` doesn't work in general,
  # because some frequencies (e.g., MonthEnd) don't correspond to a fixed length
  # of time. Instead, we use a 'typical' length estimated by averaging over a
  # small number of steps. This recovers the exact calculation when `freq` does
  # have a fixed length (e.g., is measured in seconds, minutes, etc.).
  timedelta = ((start_time + 10 * freq) - start_time) / 10.
  return (end_time - start_time) / timedelta