code: def minute_index_to_session_labels(self, index):
          if not index.is_monotonic_increasing:
              raise ValueError(
                  "Non-ordered index passed to minute_index_to_session_labels."
              )
          prev_opens = (
              self._opens.values.searchsorted(index.values, side='right') - 1
          )
          next_closes = (
              self._closes.values.searchsorted(index.values, side='left')
          )
          mismatches = (prev_opens != next_closes)
          if mismatches.any():
              bad_ix = np.flatnonzero(mismatches)[0]
              example = index[bad_ix]
              prev_day = prev_opens[bad_ix]
              prev_open, prev_close = self.schedule.iloc[prev_day]
              next_open, next_close = self.schedule.iloc[prev_day + 1]
              raise ValueError(
                  "{num} non-market minutes in minute_index_to_session_labels:\n"
                  "First Bad Minute: {first_bad}\n"
                  "Previous Session: {prev_open} -> {prev_close}\n"
                  "Next Session: {next_open} -> {next_close}"
                  .format(
                      num=mismatches.sum(),
                      first_bad=example,
                      prev_open=prev_open, prev_close=prev_close,
                      next_open=next_open, next_close=next_close)
              )
          return self.schedule.index[prev_opens]