def _index_to_dict(idx, row):
  """Convert an index (a tuple) into a dict mapping columns to index values.

  Helper method used below to apply labels to the unlabeled index tuples
  emitted by iterrows().  Relies on the fact that in a distance matrix, the
  row indices and column indices are the same.

  Args:
    idx: a distance matrix index value (a tuple); should have the same columns
      as the row's index.
    row: a Series containing a row of a distance matrix.

  Returns:
    A dict mapping index columns to index values.
  """
  return dict(list(zip(row.index.names, idx)))