(self)
| 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( |
nothing calls this directly
no test coverage detected