def ensure_string(data):
    """Ensure the data are decoded to a string if they are bytes.

    Parameters
    ----------
    data : str or bytes
    """
    if isinstance(data, str):
        return data
    elif isinstance(data, bytes):
        return data.decode("ascii", "replace")
    else:
        raise TypeError(f"Data are neither bytes nor string: {type(data)}")