MCPcopy
hub / github.com/pydata/xarray / test_modify_inplace

Method test_modify_inplace

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

Source from the content-addressed store, hash-verified

820 a["qux"] = (("time", "x"), d.T)
821
822 def test_modify_inplace(self) -> None:
823 a = Dataset()
824 vec = np.random.random((10,))
825 attributes = {"foo": "bar"}
826 a["x"] = ("x", vec, attributes)
827 assert "x" in a.coords
828 assert isinstance(a.coords["x"].to_index(), pd.Index)
829 assert_identical(a.coords["x"].variable, a.variables["x"])
830 b = Dataset()
831 b["x"] = ("x", vec, attributes)
832 assert_identical(a["x"], b["x"])
833 assert a.sizes == b.sizes
834 # this should work
835 a["x"] = ("x", vec[:5])
836 a["z"] = ("x", np.arange(5))
837 with pytest.raises(ValueError):
838 # now it shouldn't, since there is a conflicting length
839 a["x"] = ("x", vec[:4])
840 arr = np.random.random((10, 1))
841 scal = np.array(0)
842 with pytest.raises(ValueError):
843 a["y"] = ("y", arr)
844 with pytest.raises(ValueError):
845 a["y"] = ("y", scal)
846 assert "y" not in a.dims
847
848 def test_coords_properties(self) -> None:
849 # use int64 for repr consistency on windows

Callers

nothing calls this directly

Calls 4

DatasetClass · 0.90
assert_identicalFunction · 0.90
arangeMethod · 0.80
to_indexMethod · 0.45

Tested by

no test coverage detected