def _sort_table(table, mdvar):
    """ Sorts metadata category and aligns with table.

    Parameters
    ----------
    table : pd.DataFrame
        Contain sample/feature labels along with table of values.
        Rows correspond to samples, and columns correspond to features.
    mdvar : pd.Series
        Metadata values for samples.  The index must correspond to the
        index of `table`.

    Returns
    -------
    pd.DataFrame
        Aligned feature table.
    pd.Series
        Aligned metadata.
    """
    mdvar = mdvar.sort_values()
    table = table.reindex(columns=mdvar.index)
    return table, mdvar