MCPcopy Create free account
hub / github.com/pydata/xarray / test_expand_dims_error

Method test_expand_dims_error

xarray/tests/test_dataset.py:3642–3682  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

3640 assert actual.xindexes["y"].equals(expected.xindexes["y"])
3641
3642 def test_expand_dims_error(self) -> None:
3643 original = Dataset(
3644 {
3645 "x": ("a", np.random.randn(3)),
3646 "y": (["b", "a"], np.random.randn(4, 3)),
3647 "z": ("a", np.random.randn(3)),
3648 },
3649 coords={
3650 "a": np.linspace(0, 1, 3),
3651 "b": np.linspace(0, 1, 4),
3652 "c": np.linspace(0, 1, 5),
3653 },
3654 attrs={"key": "entry"},
3655 )
3656
3657 with pytest.raises(ValueError, match=r"already exists"):
3658 original.expand_dims(dim=["x"])
3659
3660 # Make sure it raises true error also for non-dimensional coordinates
3661 # which has dimension.
3662 original = original.set_coords("z")
3663 with pytest.raises(ValueError, match=r"already exists"):
3664 original.expand_dims(dim=["z"])
3665
3666 original = Dataset(
3667 {
3668 "x": ("a", np.random.randn(3)),
3669 "y": (["b", "a"], np.random.randn(4, 3)),
3670 "z": ("a", np.random.randn(3)),
3671 },
3672 coords={
3673 "a": np.linspace(0, 1, 3),
3674 "b": np.linspace(0, 1, 4),
3675 "c": np.linspace(0, 1, 5),
3676 },
3677 attrs={"key": "entry"},
3678 )
3679 with pytest.raises(TypeError, match=r"value of new dimension"):
3680 original.expand_dims({"d": 3.2})
3681 with pytest.raises(ValueError, match=r"both keyword and positional"):
3682 original.expand_dims({"d": 4}, e=4)
3683
3684 def test_expand_dims_int(self) -> None:
3685 original = Dataset(

Callers

nothing calls this directly

Calls 4

expand_dimsMethod · 0.95
set_coordsMethod · 0.95
DatasetClass · 0.90
linspaceMethod · 0.80

Tested by

no test coverage detected