docs: def finish (self, key1set, key2set, mask=True):
          """Returns (weights, means, variances), where:
  
          weights
            ndarray of number of samples per key; shape (n1, n2), where n1 is the
            size of key1set and n2 is the size of key2set.
          means
            computed mean value for each key
          variances
            computed variance for each key
  
          """
          n1_us = len (self._key1map)
          n2_us = len (self._key2map)
          wt_us = self._m0[:n1_us,:n2_us]
          badwt = (wt_us == 0) | ~np.isfinite (wt_us)
          wt_us[badwt] = 1
          mean_us = self._m1[:n1_us,:n2_us] / wt_us
          var_us = self._m2[:n1_us,:n2_us] / wt_us - mean_us**2
          wt_us[badwt] = 0
          mean_us[badwt] = np.nan
          var_us[badwt] = np.nan
  
          n1_them = len (key1set)
          n2_them = len (key2set)
          wt = np.zeros ((n1_them, n2_them), dtype=self._m0.dtype)
          mean = np.empty ((n1_them, n2_them), dtype=self._m1.dtype)
          mean.fill (np.nan)
          var = np.empty_like (mean)
          var.fill (np.nan)
  
          # You can't fancy-index on two axes simultaneously, so we do a manual
          # loop on the first axis.
  
          us_idx2 = []
          them_idx2 = []
  
          for them_i2, key2 in enumerate (key2set):
              us_i2 = self._key2map[key2]
              if us_i2 < n2_us:
                  them_idx2.append (them_i2)
                  us_idx2.append (us_i2)
              # otherwise, we must not have seen that key
  
          for them_i1, key1 in enumerate (key1set):
              us_i1 = self._key1map[key1]
              if us_i1 >= n1_us:
                  continue # don't have this key
  
              wt[them_i1,them_idx2] = wt_us[us_i1,us_idx2]
              mean[them_i1,them_idx2] = mean_us[us_i1,us_idx2]
              var[them_i1,them_idx2] = var_us[us_i1,us_idx2]
  
          if mask:
              m = ~np.isfinite (mean)
              mean = np.ma.MaskedArray (mean, m)
              var = np.ma.MaskedArray (var, m)
  
          self._m0 = self._m1 = self._m2 = None
          self._key1map.clear ()
          self._key2map.clear ()
  
          return wt, mean, var