diff --git a/xarray/core/variable.py b/xarray/core/variable.py index 1f18f61441c..e89cf95411c 100644 --- a/xarray/core/variable.py +++ b/xarray/core/variable.py @@ -123,13 +123,18 @@ def as_variable( if isinstance(obj, Variable): obj = obj.copy(deep=False) elif isinstance(obj, tuple): - if isinstance(obj[1], DataArray): + try: + dims_, data_, *attrs = obj + except ValueError: + raise ValueError(f"Tuple {obj} is not in the form (dims, data[, attrs])") + + if isinstance(data_, DataArray): raise TypeError( f"Variable {name!r}: Using a DataArray object to construct a variable is" " ambiguous, please extract the data using the .data property." ) try: - obj = Variable(*obj) + obj = Variable(dims_, data_, *attrs) except (TypeError, ValueError) as error: raise error.__class__( f"Variable {name!r}: Could not convert tuple of form "