def map_results(results, func, as_frame=False):
    """
    Applies ``func`` to each model solution in ``results``, returning
    a pandas DataFrame (if as_frame is True) or Series,
    indexed by the run names (if available).

    """
    # TODO: add unit tests
    def map_func(x):
        try:
            return func(x)
        except Exception:
            return np.nan

    iterations = results.iterations.index
    items = [map_func(results.solutions[i]) for i in iterations]
    names = [results.solutions[i].config_run.name
             if 'name' in results.solutions[i].config_run
             else i
             for i in iterations]
    if as_frame:
        return pd.DataFrame(items, index=names)
    else:
        return pd.Series(items, index=names)
dataset/ETHPy150Open calliope-project/calliope/calliope/analysis.py/map_results/original