(self)
| 3682 | original.expand_dims({"d": 4}, e=4) |
| 3683 | |
| 3684 | def test_expand_dims_int(self) -> None: |
| 3685 | original = Dataset( |
| 3686 | {"x": ("a", np.random.randn(3)), "y": (["b", "a"], np.random.randn(4, 3))}, |
| 3687 | coords={ |
| 3688 | "a": np.linspace(0, 1, 3), |
| 3689 | "b": np.linspace(0, 1, 4), |
| 3690 | "c": np.linspace(0, 1, 5), |
| 3691 | }, |
| 3692 | attrs={"key": "entry"}, |
| 3693 | ) |
| 3694 | |
| 3695 | actual = original.expand_dims(["z"], [1]) |
| 3696 | expected = Dataset( |
| 3697 | { |
| 3698 | "x": original["x"].expand_dims("z", 1), |
| 3699 | "y": original["y"].expand_dims("z", 1), |
| 3700 | }, |
| 3701 | coords={ |
| 3702 | "a": np.linspace(0, 1, 3), |
| 3703 | "b": np.linspace(0, 1, 4), |
| 3704 | "c": np.linspace(0, 1, 5), |
| 3705 | }, |
| 3706 | attrs={"key": "entry"}, |
| 3707 | ) |
| 3708 | assert_identical(expected, actual) |
| 3709 | # make sure squeeze restores the original data set. |
| 3710 | roundtripped = actual.squeeze("z") |
| 3711 | assert_identical(original, roundtripped) |
| 3712 | |
| 3713 | # another test with a negative axis |
| 3714 | actual = original.expand_dims(["z"], [-1]) |
| 3715 | expected = Dataset( |
| 3716 | { |
| 3717 | "x": original["x"].expand_dims("z", -1), |
| 3718 | "y": original["y"].expand_dims("z", -1), |
| 3719 | }, |
| 3720 | coords={ |
| 3721 | "a": np.linspace(0, 1, 3), |
| 3722 | "b": np.linspace(0, 1, 4), |
| 3723 | "c": np.linspace(0, 1, 5), |
| 3724 | }, |
| 3725 | attrs={"key": "entry"}, |
| 3726 | ) |
| 3727 | assert_identical(expected, actual) |
| 3728 | # make sure squeeze restores the original data set. |
| 3729 | roundtripped = actual.squeeze("z") |
| 3730 | assert_identical(original, roundtripped) |
| 3731 | |
| 3732 | def test_expand_dims_coords(self) -> None: |
| 3733 | original = Dataset({"x": ("a", np.array([1, 2, 3]))}) |
nothing calls this directly
no test coverage detected