'Convert raw computed pipeline results into a DataFrame for public APIs.
Parameters
terms : dict[str -> Term]
Dict mapping column names to terms.
data : dict[str -> ndarray[ndim=2]]
Dict mapping column names to computed results for those names.
mask : ndarray[bool, ndim=2]
Mask array of values to keep.
dates : ndarray[datetime64, ndim=1]
Row index for arrays `data` and `mask`
assets : ndarray[int64, ndim=2]
Column index for arrays `data` and `mask`
Returns
results : pd.DataFrame
The indices of `results` are as follows:
index : two-tiered MultiIndex of (date, asset).
Contains an entry for each (date, asset) pair corresponding to
a `True` value in `mask`.
columns : Index of str
One column per entry in `data`.
If mask[date, asset] is True, then result.loc[(date, asset), colname]
will contain the value of data[colname][date, asset].'

def _to_narrow(self, terms, data, mask, dates, assets):

    if (not mask.any()):
        empty_dates = dates[:0]
        empty_assets = array([], dtype=object)
        return DataFrame(data={name: array([], dtype=arr.dtype) for (name, arr) in iteritems(data)}, index=MultiIndex.from_arrays([empty_dates, empty_assets]))
    resolved_assets = array(self._finder.retrieve_all(assets))
    dates_kept = repeat_last_axis(dates.values, len(assets))[mask]
    assets_kept = repeat_first_axis(resolved_assets, len(dates))[mask]
    final_columns = {}
    for name in data:
        final_columns[name] = terms[name].postprocess(data[name][mask])
    return DataFrame(data=final_columns, index=MultiIndex.from_arrays([dates_kept, assets_kept])).tz_localize('UTC', level=0)
