import logging
from warnings import warn


def find_voltage_extremes(metrics, data):
    """
    Parameters
    ----------
    metrics: dictionary
        dictionary to add to
    data: list
        time and voltage data for dictionary
    Returns
    -------
        dictionary containing voltage extremes in tuple unless
        data provided to dictionary is faulty
    Raises
    ------
        ValueError
            If data contains strings
    """
    x = [i for i in data[1] if isinstance(i, str)]
    if len(x) > 0:
        logging.error('String not expected')
        raise ValueError('String not expected')
    if (len(data[1]) == 0):
        metrics['voltage_extremes'] = ()
        warn('No voltage data available')
        return metrics
    min_v = min(data[1])
    max_v = max(data[1])
    metrics['voltage_extremes'] = (min_v, max_v)
    return metrics