def ensure_unicode(x, encoding='ascii'):
    """
    Decode bytes to unicode if necessary.

    Parameters
    ----------
    obj : bytes or unicode
    encoding : str, default "ascii"

    Returns
    -------
    unicode
    """
    if isinstance(x, bytes):
        return x.decode(encoding)
    return x