nodes: 0, module; 1, function_definition; 2, function_name:next_event_indexer; 3, parameters; 4, block; 5, identifier:all_dates; 6, identifier:data_query_cutoff; 7, identifier:all_sids; 8, identifier:event_dates; 9, identifier:event_timestamps; 10, identifier:event_sids; 11, expression_statement; 12, expression_statement; 13, expression_statement; 14, expression_statement; 15, comment:# side='right' here ensures that we include the event date itself; 16, comment:# if it's in all_dates.; 17, expression_statement; 18, expression_statement; 19, comment:# Walk backward through the events, writing the index of the event into; 20, comment:# slots ranging from the event's timestamp to its asof.  This depends for; 21, comment:# correctness on the fact that event_dates is sorted in ascending order,; 22, comment:# because we need to overwrite later events with earlier ones if their; 23, comment:# eligible windows overlap.; 24, for_statement; 25, return_statement; 26, comment:"""
      Construct an index array that, when applied to an array of values, produces
      a 2D array containing the values associated with the next event for each
      sid at each moment in time.
  
      Locations where no next event was known will be filled with -1.
  
      Parameters
      ----------
      all_dates : ndarray[datetime64[ns], ndim=1]
          Row labels for the target output.
      data_query_cutoff : pd.DatetimeIndex
          The boundaries for the given trading sessions in ``all_dates``.
      all_sids : ndarray[int, ndim=1]
          Column labels for the target output.
      event_dates : ndarray[datetime64[ns], ndim=1]
          Dates on which each input events occurred/will occur.  ``event_dates``
          must be in sorted order, and may not contain any NaT values.
      event_timestamps : ndarray[datetime64[ns], ndim=1]
          Dates on which we learned about each input event.
      event_sids : ndarray[int, ndim=1]
          Sids assocated with each input event.
  
      Returns
      -------
      indexer : ndarray[int, ndim=2]
          An array of shape (len(all_dates), len(all_sids)) of indices into
          ``event_{dates,timestamps,sids}``.
      """; 27, call; 28, assignment; 29, assignment; 30, assignment; 31, assignment; 32, identifier:i; 33, call; 34, block; 35, identifier:out; 36, identifier:validate_event_metadata; 37, argument_list; 38, identifier:out; 39, call; 40, identifier:sid_ixs; 41, call; 42, identifier:dt_ixs; 43, call; 44, identifier:ts_ixs; 45, call; 46, identifier:range; 47, argument_list; 48, expression_statement; 49, expression_statement; 50, expression_statement; 51, identifier:event_dates; 52, identifier:event_timestamps; 53, identifier:event_sids; 54, attribute; 55, argument_list; 56, attribute; 57, argument_list; 58, attribute; 59, argument_list; 60, attribute; 61, argument_list; 62, binary_operator:len(event_sids) - 1; 63, unary_operator; 64, unary_operator; 65, assignment; 66, assignment; 67, assignment; 68, identifier:np; 69, identifier:full; 70, tuple; 71, unary_operator; 72, keyword_argument; 73, identifier:all_sids; 74, identifier:searchsorted; 75, identifier:event_sids; 76, identifier:all_dates; 77, identifier:searchsorted; 78, identifier:event_dates; 79, keyword_argument; 80, identifier:data_query_cutoff; 81, identifier:searchsorted; 82, identifier:event_timestamps; 83, keyword_argument; 84, call; 85, integer:1; 86, integer:1; 87, integer:1; 88, identifier:start_ix; 89, subscript; 90, identifier:end_ix; 91, subscript; 92, subscript; 93, identifier:i; 94, call; 95, call; 96, integer:1; 97, identifier:dtype; 98, attribute; 99, identifier:side; 100, string; 101, identifier:side; 102, string; 103, identifier:len; 104, argument_list; 105, identifier:ts_ixs; 106, identifier:i; 107, identifier:dt_ixs; 108, identifier:i; 109, identifier:out; 110, slice; 111, subscript; 112, identifier:len; 113, argument_list; 114, identifier:len; 115, argument_list; 116, identifier:np; 117, identifier:int64; 118, string_content:right; 119, string_content:right; 120, identifier:event_sids; 121, identifier:start_ix; 122, identifier:end_ix; 123, identifier:sid_ixs; 124, identifier:i; 125, identifier:all_dates; 126, identifier:all_sids
code: def next_event_indexer(all_dates,
                         data_query_cutoff,
                         all_sids,
                         event_dates,
                         event_timestamps,
                         event_sids):
      """
      Construct an index array that, when applied to an array of values, produces
      a 2D array containing the values associated with the next event for each
      sid at each moment in time.
  
      Locations where no next event was known will be filled with -1.
  
      Parameters
      ----------
      all_dates : ndarray[datetime64[ns], ndim=1]
          Row labels for the target output.
      data_query_cutoff : pd.DatetimeIndex
          The boundaries for the given trading sessions in ``all_dates``.
      all_sids : ndarray[int, ndim=1]
          Column labels for the target output.
      event_dates : ndarray[datetime64[ns], ndim=1]
          Dates on which each input events occurred/will occur.  ``event_dates``
          must be in sorted order, and may not contain any NaT values.
      event_timestamps : ndarray[datetime64[ns], ndim=1]
          Dates on which we learned about each input event.
      event_sids : ndarray[int, ndim=1]
          Sids assocated with each input event.
  
      Returns
      -------
      indexer : ndarray[int, ndim=2]
          An array of shape (len(all_dates), len(all_sids)) of indices into
          ``event_{dates,timestamps,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)
      # side='right' here ensures that we include the event date itself
      # if it's in all_dates.
      dt_ixs = all_dates.searchsorted(event_dates, side='right')
      ts_ixs = data_query_cutoff.searchsorted(event_timestamps, side='right')
  
      # Walk backward through the events, writing the index of the event into
      # slots ranging from the event's timestamp to its asof.  This depends for
      # correctness on the fact that event_dates is sorted in ascending order,
      # because we need to overwrite later events with earlier ones if their
      # eligible windows overlap.
      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