code: def next_event_indexer(all_dates,
                         data_query_cutoff,
                         all_sids,
                         event_dates,
                         event_timestamps,
                         event_sids):
      validate_event_metadata(event_dates, event_timestamps, event_sids)
      out = np.full((len(all_dates), len(all_sids)), -1, dtype=np.int64)
      sid_ixs = all_sids.searchsorted(event_sids)
      dt_ixs = all_dates.searchsorted(event_dates, side='right')
      ts_ixs = data_query_cutoff.searchsorted(event_timestamps, side='right')
      for i in range(len(event_sids) - 1, -1, -1):
          start_ix = ts_ixs[i]
          end_ix = dt_ixs[i]
          out[start_ix:end_ix, sid_ixs[i]] = i
      return out