code: def _regularize(x, y, ties):
      
      x, y = [
          column_or_1d(check_array(arr, ensure_2d=False,
                                   force_all_finite=False,
                                   dtype=DTYPE))
          for arr in (x, y)
      ]
  
      nx = x.shape[0]
      if nx != y.shape[0]:
          raise ValueError('array dim mismatch: %i != %i' % (nx, y.shape[0]))
  
      # manipulate x if needed. if ties is 'ordered' we assume that x is
      # already ordered and everything has been handled already...
      if ties != 'ordered':
          o = np.argsort(x)
  
          # keep ordered with one another
          x = x[o]
          y = y[o]
  
          # what if any are the same?
          ux = np.unique(x)
          if ux.shape[0] < nx:
              # Do we want to warn for this?
              # warnings.warn('collapsing to unique "x" values')
  
              # vectorize this function to apply to each "cell" in the array
              def tie_apply(f, u_val):
                  vals = y[x == u_val]  # mask y where x == the unique value
                  return f(vals)
  
              # replace the duplicates in the y array with the "tie" func
              func = VALID_TIES.get(ties, _identity)
  
              # maybe expensive to vectorize on the fly? Not sure; would need
              # to do some benchmarking. However, we need to in order to keep y
              # and x in scope...
              y = np.vectorize(tie_apply)(func, ux)
  
              # does ux need ordering? hmm..
              x = ux
  
      return x, y
docs: Regularize the values, make them ordered and remove duplicates.
      If the ``ties`` parameter is explicitly set to 'ordered' then order
      is already assumed. Otherwise, the removal process will happen.
  
      Parameters
      ----------
      x : array-like, shape=(n_samples,)
          The x vector.
  
      y : array-like, shape=(n_samples,)
          The y vector.
  
      ties : str
          One of {'ordered', 'mean'}, handles the ties.