def _as_dataset_variable(name, var):
    """Prepare a variable for adding it to a Dataset
    """
    try:
        var = as_variable(var, key=name)
    except __HOLE__:
        raise TypeError('variables must be given by arrays or a tuple of '
                        'the form (dims, data[, attrs, encoding])')
    if name in var.dims:
        # convert the into an Index
        if var.ndim != 1:
            raise ValueError('the variable %r has the same name as one of its '
                             'dimensions %r, but it is not 1-dimensional and '
                             'thus it is not a valid index' % (name, var.dims))
        var = var.to_coord()
    return var
dataset/ETHPy150Open pydata/xarray/xarray/core/merge.py/_as_dataset_variable