(self)
| 902 | } |
| 903 | |
| 904 | def test_coords_modify(self) -> None: |
| 905 | data = Dataset( |
| 906 | { |
| 907 | "x": ("x", [-1, -2]), |
| 908 | "y": ("y", [0, 1, 2]), |
| 909 | "foo": (["x", "y"], np.random.randn(2, 3)), |
| 910 | }, |
| 911 | {"a": ("x", [4, 5]), "b": -10}, |
| 912 | ) |
| 913 | |
| 914 | actual = data.copy(deep=True) |
| 915 | actual.coords["x"] = ("x", ["a", "b"]) |
| 916 | assert_array_equal(actual["x"], ["a", "b"]) |
| 917 | |
| 918 | actual = data.copy(deep=True) |
| 919 | actual.coords["z"] = ("z", ["a", "b"]) |
| 920 | assert_array_equal(actual["z"], ["a", "b"]) |
| 921 | |
| 922 | actual = data.copy(deep=True) |
| 923 | with pytest.raises(ValueError, match=r"conflicting dimension sizes"): |
| 924 | actual.coords["x"] = ("x", [-1]) |
| 925 | assert_identical(actual, data) # should not be modified |
| 926 | |
| 927 | actual = data.copy() |
| 928 | del actual.coords["b"] |
| 929 | expected = data.reset_coords("b", drop=True) |
| 930 | assert_identical(expected, actual) |
| 931 | |
| 932 | with pytest.raises(KeyError): |
| 933 | del data.coords["not_found"] |
| 934 | |
| 935 | with pytest.raises(KeyError): |
| 936 | del data.coords["foo"] |
| 937 | |
| 938 | actual = data.copy(deep=True) |
| 939 | actual.coords.update({"c": 11}) |
| 940 | expected = data.merge({"c": 11}).set_coords("c") |
| 941 | assert_identical(expected, actual) |
| 942 | |
| 943 | # regression test for GH3746 |
| 944 | del actual.coords["x"] |
| 945 | assert "x" not in actual.xindexes |
| 946 | |
| 947 | def test_update_index(self) -> None: |
| 948 | actual = Dataset(coords={"x": [1, 2, 3]}) |
nothing calls this directly
no test coverage detected