def fromtriallist(samples, targets, trials):
    """
    Return a samples and targets data frame filtered by a list of trial names.
    """
    if not isinstance(trials, list):
        raise ValueError("Trials argument must be a list.")

    samples = samples.swaplevel(0,2,axis=0).sort_index(axis=0).loc[(trials,),:].swaplevel(0,2,axis=0).sort_index(axis=0)
    targets = targets.swaplevel(0,2,axis=0).sort_index(axis=0).loc[(trials,),:].swaplevel(0,2,axis=0).sort_index(axis=0)

    return samples, targets