import warnings


def retrieve_fields(data, fields, optional_fields=[]):
    """
    Takes a dictionary (data) and list of fields. Returns the subset of data
    containing the specified fields. Any optional fields that are not present
    are replaced with an empty string.
    """
    output_fields = {}
    for field in fields:
        if field not in data.keys() and field not in optional_fields:
            warnings.warn(f'Field {field} not found', UserWarning)
        elif field not in data.keys() and field in optional_fields:
            output_fields[field] = ''
        else:
            output_fields[field] = data[field]
    return output_fields