(self)
| 4815 | assert_identical(ds, expected) |
| 4816 | |
| 4817 | def test_setitem_with_coords(self) -> None: |
| 4818 | # Regression test for GH:2068 |
| 4819 | ds = create_test_data() |
| 4820 | |
| 4821 | other = DataArray( |
| 4822 | np.arange(10), dims="dim3", coords={"numbers": ("dim3", np.arange(10))} |
| 4823 | ) |
| 4824 | expected = ds.copy() |
| 4825 | expected["var3"] = other.drop_vars("numbers") |
| 4826 | actual = ds.copy() |
| 4827 | actual["var3"] = other |
| 4828 | assert_identical(expected, actual) |
| 4829 | assert "numbers" in other.coords # should not change other |
| 4830 | |
| 4831 | # with alignment |
| 4832 | other = ds["var3"].isel(dim3=slice(1, -1)) |
| 4833 | other["numbers"] = ("dim3", np.arange(8)) |
| 4834 | actual = ds.copy() |
| 4835 | actual["var3"] = other |
| 4836 | assert "numbers" in other.coords # should not change other |
| 4837 | expected = ds.copy() |
| 4838 | expected["var3"] = ds["var3"].isel(dim3=slice(1, -1)) |
| 4839 | assert_identical(expected, actual) |
| 4840 | |
| 4841 | # with non-duplicate coords |
| 4842 | other = ds["var3"].isel(dim3=slice(1, -1)) |
| 4843 | other["numbers"] = ("dim3", np.arange(8)) |
| 4844 | other["position"] = ("dim3", np.arange(8)) |
| 4845 | actual = ds.copy() |
| 4846 | actual["var3"] = other |
| 4847 | assert "position" in actual |
| 4848 | assert "position" in other.coords |
| 4849 | |
| 4850 | # assigning a coordinate-only dataarray |
| 4851 | actual = ds.copy() |
| 4852 | other = actual["numbers"] |
| 4853 | other[0] = 10 |
| 4854 | actual["numbers"] = other |
| 4855 | assert actual["numbers"][0] == 10 |
| 4856 | |
| 4857 | # GH: 2099 |
| 4858 | ds = Dataset( |
| 4859 | {"var": ("x", [1, 2, 3])}, |
| 4860 | coords={"x": [0, 1, 2], "z1": ("x", [1, 2, 3]), "z2": ("x", [1, 2, 3])}, |
| 4861 | ) |
| 4862 | ds["var"] = ds["var"] * 2 |
| 4863 | assert np.allclose(ds["var"], [2, 4, 6]) |
| 4864 | |
| 4865 | def test_setitem_align_new_indexes(self) -> None: |
| 4866 | ds = Dataset({"foo": ("x", [1, 2, 3])}, {"x": [0, 1, 2]}) |
nothing calls this directly
no test coverage detected