code: def rank(self, dim, pct=False):
          
          import bottleneck as bn
  
          if isinstance(self.data, dask_array_type):
              raise TypeError("rank does not work for arrays stored as dask "
                              "arrays. Load the data via .compute() or .load() "
                              "prior to calling this method.")
  
          axis = self.get_axis_num(dim)
          func = bn.nanrankdata if self.dtype.kind == 'f' else bn.rankdata
          ranked = func(self.data, axis=axis)
          if pct:
              count = np.sum(~np.isnan(self.data), axis=axis, keepdims=True)
              ranked /= count
          return Variable(self.dims, ranked)
docs: Ranks the data.
  
          Equal values are assigned a rank that is the average of the ranks that
          would have been otherwise assigned to all of the values within that
          set.  Ranks begin at 1, not 0. If `pct`, computes percentage ranks.
  
          NaNs in the input array are returned as NaNs.
  
          The `bottleneck` library is required.
  
          Parameters
          ----------
          dim : str
              Dimension over which to compute rank.
          pct : bool, optional
              If True, compute percentage ranks, otherwise compute integer ranks.
  
          Returns
          -------
          ranked : Variable
  
          See Also
          --------
          Dataset.rank, DataArray.rank