Skip to content

Commit 3a8de48

Browse files
committed
Add tests
1 parent 870a60e commit 3a8de48

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

xarray/tests/test_dataarray.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,6 +1702,11 @@ def should_add_coord_to_array(self, name, var, dims):
17021702
assert_identical(actual, expected, check_default_indexes=False)
17031703
assert "x_bnds" not in actual.dims
17041704

1705+
def test_assign_coords_uses_base_variable_class(self) -> None:
1706+
a = DataArray([0, 1, 2], dims=["x"], coords={"x": [0, 1, 2]})
1707+
a = a.assign_coords(foo=a.x)
1708+
assert not isinstance(a["foo"].variable, IndexVariable)
1709+
17051710
def test_coords_alignment(self) -> None:
17061711
lhs = DataArray([1, 2, 3], [("x", [0, 1, 2])])
17071712
rhs = DataArray([2, 3, 4], [("x", [1, 2, 3])])

xarray/tests/test_dataset.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4779,6 +4779,11 @@ def test_setitem_using_list_errors(self, var_list, data, error_regex) -> None:
47794779
with pytest.raises(ValueError, match=error_regex):
47804780
actual[var_list] = data
47814781

4782+
def test_setitem_uses_base_variable_class_even_for_index_variables(self) -> None:
4783+
ds = Dataset(coords={"x": [1, 2, 3]})
4784+
ds["y"] = ds["x"]
4785+
assert not isinstance(ds["y"].variable, IndexVariable)
4786+
47824787
def test_assign(self) -> None:
47834788
ds = Dataset()
47844789
actual = ds.assign(x=[0, 1, 2], y=2)

0 commit comments

Comments
 (0)