def METHOD_NAME(levels):
    """ Return sparse coords and dense labels for subset levels """
    # TODO: how to do this better? cleanly slice nonnull_labels given the
    # coord
    values_ilabels = [tuple(x[i] for i in levels)
                      for x in nonnull_labels.index]
    if len(levels) == 1:
        values_ilabels = [x[0] for x in values_ilabels]
    # # performance issues with groupby ###################################
    # TODO: these two lines can rejplace the code below but
    # groupby is too slow (in some cases at least)
    # labels_to_i = ss.groupby(level=levels, sort=sort_labels).first()
    # labels_to_i[:] = np.arange(labels_to_i.shape[0])
    def _get_label_to_i_dict(labels, sort_labels=False):
        """ Return OrderedDict of unique labels to number.
        Optionally sort by label.
        """
        labels = Index(lmap(tuple, labels)).unique().tolist()  # squish
        if sort_labels:
            labels = sorted(list(labels))
        d = OrderedDict((k, i) for i, k in enumerate(labels))
        return (d)
    def _get_index_subset_to_coord_dict(index, subset, sort_labels=False):
        ilabels = list(zip(*[index._get_level_values(i) for i in subset]))
        labels_to_i = _get_label_to_i_dict(ilabels,
                                           sort_labels=sort_labels)
        labels_to_i = Series(labels_to_i)
        if len(subset) > 1:
            labels_to_i.index = MultiIndex.from_tuples(labels_to_i.index)
            labels_to_i.index.names = [index.names[i] for i in subset]
        else:
            labels_to_i.index = Index(x[0] for x in labels_to_i.index)
            labels_to_i.index.name = index.names[subset[0]]
        labels_to_i.name = 'value'
        return (labels_to_i)
    labels_to_i = _get_index_subset_to_coord_dict(ss.index, levels,
                                                  sort_labels=sort_labels)
    # #####################################################################
    # #####################################################################
    i_coord = labels_to_i[values_ilabels].tolist()
    i_labels = labels_to_i.index.tolist()
    return i_coord, i_labels