def previous_event_indexer(all_dates, 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)
 eff_dts = np.maximum(event_dates, event_timestamps)
 sid_ixs = all_sids.searchsorted(event_sids)
 dt_ixs = all_dates.searchsorted(eff_dts)
 last_written = {}
 for i in range((len(event_dates) - 1), (-1), (-1)):
  sid_ix = sid_ixs[i]
  dt_ix = dt_ixs[i]
  out[dt_ix:last_written.get(sid_ix, None), sid_ix] = i
  last_written[sid_ix] = dt_ix
 return out

def previous_event_indexer ( all_dates , 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 ) eff_dts = np . maximum ( event_dates , event_timestamps ) sid_ixs = all_sids . searchsorted ( event_sids ) dt_ixs = all_dates . searchsorted ( eff_dts ) last_written = { } for i in range ( ( len ( event_dates ) - 1 ) , ( - 1 ) , ( - 1 ) ) : sid_ix = sid_ixs [ i ] dt_ix = dt_ixs [ i ] out [ dt_ix : last_written . get ( sid_ix , None ) , sid_ix ] = i last_written [ sid_ix ] = dt_ix return out
construct an index array that .