Skip to content

Commit 5164d1e

Browse files
committed
fix tests
1 parent ec27da4 commit 5164d1e

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

xarray/core/variable.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def as_variable(obj, name=None) -> Variable | IndexVariable:
163163
if obj.ndim != 1:
164164
warnings.warn(
165165
f"{name!r} has more than 1-dimension and the same name as one of its "
166-
f"dimensions {obj.dims!r}. Xarray will not automatically"
166+
f"dimensions {obj.dims!r}. Xarray will not automatically "
167167
"create an Index object that would allow label-based selection.",
168168
RuntimeWarning,
169169
)

xarray/tests/test_dataset.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,13 +467,15 @@ def test_constructor(self) -> None:
467467

468468
with pytest.raises(ValueError, match=r"conflicting sizes"):
469469
Dataset({"a": x1, "b": x2})
470-
with pytest.raises(ValueError, match=r"disallows such variables"):
471-
Dataset({"a": x1, "x": z})
472470
with pytest.raises(TypeError, match=r"tuple of form"):
473471
Dataset({"x": (1, 2, 3, 4, 5, 6, 7)})
474472
with pytest.raises(ValueError, match=r"already exists as a scalar"):
475473
Dataset({"x": 0, "y": ("x", [1, 2, 3])})
476474

475+
with pytest.warns(RuntimeWarning, match=r"will not automatically"):
476+
actual = Dataset({"a": x1, "x": z})
477+
assert "x" not in actual.xindexes
478+
477479
# verify handling of DataArrays
478480
expected = Dataset({"x": x1, "z": z})
479481
actual = Dataset({"z": expected["z"]})

xarray/tests/test_variable.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,8 +1247,9 @@ def test_as_variable(self):
12471247
expected = Variable(("x", "y"), data)
12481248
with pytest.raises(ValueError, match=r"without explicit dimension names"):
12491249
as_variable(data, name="x")
1250-
with pytest.raises(ValueError, match=r"has more than 1-dimension"):
1251-
as_variable(expected, name="x")
1250+
with pytest.warns(RuntimeWarning, match=r"has more than 1-dimension"):
1251+
actual = as_variable(expected, name="x")
1252+
assert_identical(expected, actual)
12521253

12531254
# test datetime, timedelta conversion
12541255
dt = np.array([datetime(1999, 1, 1) + timedelta(days=x) for x in range(10)])

0 commit comments

Comments
 (0)