@classmethod
def select_mask(cls, dataset, selection):
    """
        Given a Dataset object and a dictionary with dimension keys and
        selection keys (i.e tuple ranges, slices, sets, lists or literals)
        return a boolean mask over the rows in the Dataset object that
        have been selected.
        """
    select_mask = None
    for dim, k in selection.items():
        if isinstance(k, tuple):
            k = slice(*k)
        masks = []
        alias = dataset.get_dimension(dim).name
        series = dataset.data[alias]
        if isinstance(k, slice):
            if k.start is not None:
                masks.append(k.start <= series)
            if k.stop is not None:
                masks.append(series < k.stop)
        elif isinstance(k, (set, list)):
            iter_slc = None
            for ik in k:
                mask = series == ik
                if iter_slc is None:
                    iter_slc = mask
                else:
                    iter_slc |= mask
            masks.append(iter_slc)
        elif callable(k):
            masks.append(k(series))
        else:
            masks.append(series == k)
        for mask in masks:
            if select_mask:
                select_mask &= mask
            else:
                select_mask = mask
    return select_mask
