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

Method test_coords_properties

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

Source from the content-addressed store, hash-verified

846 assert "y" not in a.dims
847
848 def test_coords_properties(self) -> None:
849 # use int64 for repr consistency on windows
850 data = Dataset(
851 {
852 "x": ("x", np.array([-1, -2], "int64")),
853 "y": ("y", np.array([0, 1, 2], "int64")),
854 "foo": (["x", "y"], np.random.randn(2, 3)),
855 },
856 {"a": ("x", np.array([4, 5], "int64")), "b": np.int64(-10)},
857 )
858
859 coords = data.coords
860 assert isinstance(coords, DatasetCoordinates)
861
862 # len
863 assert len(coords) == 4
864
865 # iter
866 assert list(coords) == ["x", "y", "a", "b"]
867
868 assert_identical(coords["x"].variable, data["x"].variable)
869 assert_identical(coords["y"].variable, data["y"].variable)
870
871 assert "x" in coords
872 assert "a" in coords
873 assert 0 not in coords
874 assert "foo" not in coords
875
876 with pytest.raises(KeyError):
877 coords["foo"]
878 with pytest.raises(KeyError):
879 coords[0]
880
881 # repr
882 expected = dedent(
883 """\
884 Coordinates:
885 * x (x) int64 16B -1 -2
886 a (x) int64 16B 4 5
887 * y (y) int64 24B 0 1 2
888 b int64 8B -10"""
889 )
890 actual = repr(coords)
891 assert expected == actual
892
893 # dims
894 assert coords.sizes == {"x": 2, "y": 3}
895
896 # dtypes
897 assert coords.dtypes == {
898 "x": np.dtype("int64"),
899 "y": np.dtype("int64"),
900 "a": np.dtype("int64"),
901 "b": np.dtype("int64"),
902 }
903
904 def test_coords_modify(self) -> None:
905 data = Dataset(

Callers

nothing calls this directly

Calls 3

DatasetClass · 0.90
assert_identicalFunction · 0.90
dtypeMethod · 0.45

Tested by

no test coverage detected