def ffill_digest_frame_from_prior_values(field, digest_frame, prior_values):
    """
    Forward-fill a digest frame, falling back to the last known priof values if
    necessary.
    """
    if digest_frame is not None:
        # Digest frame is None in the case that we only have length 1 history
        # specs for a given frequency.

        # It's possible that the first bar in our digest frame is storing NaN
        # values. If so, check if we've tracked an older value and use that as
        # an ffill value for the first bar.
        first_bar = digest_frame.ix[0]
        nan_sids = first_bar[first_bar.isnull()].index
        for sid in nan_sids:
            try:
                # Only use prior value if it is before the index,
                # so that a backfill does not accidentally occur.
                if prior_values[field][sid]['dt'] <= digest_frame.index[0]:
                    digest_frame[sid][0] = prior_values[field][sid]['value']

            except KeyError:
                # Allow case where there is no previous value.
                # e.g. with leading nans.
                pass
        digest_frame = digest_frame.ffill()
    return digest_frame