'Ensure that min_extra_rows pushes us back to a computation date.
Parameters
all_dates : pd.DatetimeIndex
The trading sessions against which ``self`` will be computed.
start_date : pd.Timestamp
The first date for which final output is requested.
end_date : pd.Timestamp
The last date for which final output is requested.
min_extra_rows : int
The minimum number of extra rows required of ``self``, as
determined by other terms that depend on ``self``.
Returns
extra_rows : int
The number of extra rows to compute.  This will be the minimum
number of rows required to make our computed start_date fall on a
recomputation date.'

def compute_extra_rows(self, all_dates, start_date, end_date, min_extra_rows):

    try:
        current_start_pos = (all_dates.get_loc(start_date) - min_extra_rows)
        if (current_start_pos < 0):
            raise NoFurtherDataError(initial_message='Insufficient    data    to    compute    Pipeline:', first_date=all_dates[0], lookback_start=start_date, lookback_length=min_extra_rows)
    except KeyError:
        (before, after) = nearest_unequal_elements(all_dates, start_date)
        raise ValueError('Pipeline    start_date    {start_date}    is    not    in    calendar.\nLatest    date    before    start_date    is    {before}.\nEarliest    date    after    start_date    is    {after}.'.format(start_date=start_date, before=before, after=after))
    candidates = all_dates[:(current_start_pos + 1)]
    choices = select_sampling_indices(candidates, self._frequency)
    new_start_date = candidates[choices[(-1)]]
    new_start_pos = all_dates.get_loc(new_start_date)
    assert (new_start_pos <= current_start_pos), 'Computed    negative    extra    rows!'
    return (min_extra_rows + (current_start_pos - new_start_pos))
