Skip to content

Commit

Permalink
raise a TypeError when passing DataArray to Variable
Browse files Browse the repository at this point in the history
  • Loading branch information
keewis committed Jul 22, 2021
1 parent 986b8fd commit c6b33e6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
11 changes: 3 additions & 8 deletions xarray/core/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,9 @@ def as_variable(obj, name=None) -> "Union[Variable, IndexVariable]":
obj = obj.copy(deep=False)
elif isinstance(obj, tuple):
if isinstance(obj[1], DataArray):
# TODO: change into TypeError
warnings.warn(
(
"Using a DataArray object to construct a variable is"
" ambiguous, please extract the data using the .data property."
" This will raise a TypeError in 0.19.0."
),
DeprecationWarning,
raise TypeError(
"Using a DataArray object to construct a variable is"
" ambiguous, please extract the data using the .data property."
)
try:
obj = Variable(*obj)
Expand Down
2 changes: 1 addition & 1 deletion xarray/tests/test_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,7 @@ def test_as_variable(self):
td = np.array([timedelta(days=x) for x in range(10)])
assert as_variable(td, "time").dtype.kind == "m"

with pytest.warns(DeprecationWarning):
with pytest.raises(TypeError):
as_variable(("x", DataArray([])))

def test_repr(self):
Expand Down

0 comments on commit c6b33e6

Please sign in to comment.