def next_event_frame(events_by_sid,
                     dates,
                     missing_value,
                     field_dtype,
                     event_date_field_name,
                     return_field_name):
    date_cols = {
        equity: np.full_like(dates, NaTns) for equity in events_by_sid
    }
    value_cols = {
        equity: np.full(len(dates), missing_value, dtype=field_dtype)
        for equity in events_by_sid
    }

    raw_dates = dates.values
    for equity, df in iteritems(events_by_sid):
        event_dates = df[event_date_field_name]
        values = df[return_field_name]
        data = date_cols[equity]
        if not event_dates.index.is_monotonic_increasing:
            event_dates = event_dates.sort_index()

        # Iterate over the raw Series values, since we're comparing against
        # numpy arrays anyway.
        iter_date_vals = zip(event_dates.index.values, event_dates.values,
                             values)
        for knowledge_date, event_date, value in iter_date_vals:
            date_mask = (
                (knowledge_date <= raw_dates) &
                (raw_dates <= event_date)
            )
            value_mask = (event_date <= data) | (data == NaTns)
            data_indices = np.where(date_mask & value_mask)
            data[data_indices] = event_date
            value_cols[equity][data_indices] = value
    return pd.DataFrame(index=dates, data=value_cols)
Make a DataFrame representing the simulated next known dates or values
dataset/ETHPy150Open quantopian/zipline/zipline/pipeline/loaders/utils.py/next_event_frame