def transfer_cutoff_times(entityset, cutoff_times, source_entity, target_entity, reduce='latest'):
    path = find_path(entityset, source_entity, target_entity)[(- 1)]
    for (i, source) in enumerate(path[:(- 1)]):
        target = path[(i + 1)]
        options = list(filter((lambda r: (((r.child_entity.id == source) and (r.parent_entity.id == target)) or ((r.parent_entity.id == source) and (r.child_entity.id == target)))), entityset.relationships))
        if (len(options) == 0):
            raise ValueError('No Relationship between {} and {}'.format(source, target))
        r = options[0]
        if (target == r.child_entity.id):
            child_df_index = r.child_entity.df[r.child_variable.id].values
            cutoff_times = cutoff_times.loc[child_df_index]
            cutoff_times.index = r.child_entity.df.index
        elif (source == r.child_entity.id):
            cutoff_times[r.child_variable.id] = r.child_entity.df[r.child_variable.id]
            if (reduce == 'latest'):
                idx = cutoff_times.groupby(r.child_variable.id).time.idxmax().values
            elif (reduce == 'earist'):
                idx = cutoff_times.groupby(r.child_variable.id).time.idxmin().values
            else:
                raise ValueError('Unknown reduce option.')
            cutoff_times = cutoff_times.loc[idx]
            cutoff_times = cutoff_times.set_index(r.child_variable.id, drop=True)
    return cutoff_times
def transfer_cutoff_times(entityset, cutoff_times, source_entity, target_entity, reduce='latest'):
    path = find_path(entityset, source_entity, target_entity)[(- 1)]
    for (i, source) in enumerate(path[:(- 1)]):
        target = path[(i + 1)]
        options = list(filter((lambda r: (((r.child_entity.id == source) and (r.parent_entity.id == target)) or ((r.parent_entity.id == source) and (r.child_entity.id == target)))), entityset.relationships))
        if (len(options) == 0):
            raise ValueError('No Relationship between {} and {}'.format(source, target))
        r = options[0]
        if (target == r.child_entity.id):
            child_df_index = r.child_entity.df[r.child_variable.id].values
            cutoff_times = cutoff_times.loc[child_df_index]
            cutoff_times.index = r.child_entity.df.index
        elif (source == r.child_entity.id):
            cutoff_times[r.child_variable.id] = r.child_entity.df[r.child_variable.id]
            if (reduce == 'latest'):
                idx = cutoff_times.groupby(r.child_variable.id).time.idxmax().values
            elif (reduce == 'earist'):
                idx = cutoff_times.groupby(r.child_variable.id).time.idxmin().values
            else:
                raise ValueError('Unknown reduce option.')
            cutoff_times = cutoff_times.loc[idx]
            cutoff_times = cutoff_times.set_index(r.child_variable.id, drop=True)
    return cutoff_times