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

Method test_data_vars_properties

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

Source from the content-addressed store, hash-verified

1061 assert_identical(expected, actual)
1062
1063 def test_data_vars_properties(self) -> None:
1064 ds = Dataset()
1065 ds["foo"] = (("x",), [1.0])
1066 ds["bar"] = 2.0
1067
1068 # iter
1069 assert set(ds.data_vars) == {"foo", "bar"}
1070 assert "foo" in ds.data_vars
1071 assert "x" not in ds.data_vars
1072 assert_identical(ds["foo"], ds.data_vars["foo"])
1073
1074 # repr
1075 expected = dedent(
1076 """\
1077 Data variables:
1078 foo (x) float64 8B 1.0
1079 bar float64 8B 2.0"""
1080 )
1081 actual = repr(ds.data_vars)
1082 assert expected == actual
1083
1084 # dtypes
1085 assert ds.data_vars.dtypes == {
1086 "foo": np.dtype("float64"),
1087 "bar": np.dtype("float64"),
1088 }
1089
1090 # len
1091 ds.coords["x"] = [1]
1092 assert len(ds.data_vars) == 2
1093
1094 # https://github.com/pydata/xarray/issues/7588
1095 with pytest.raises(
1096 AssertionError, match=r"something is wrong with Dataset._coord_names"
1097 ):
1098 ds._coord_names = {"w", "x", "y", "z"}
1099 len(ds.data_vars)
1100
1101 def test_equals_and_identical(self) -> None:
1102 data = create_test_data(seed=42)

Callers

nothing calls this directly

Calls 3

DatasetClass · 0.90
assert_identicalFunction · 0.90
dtypeMethod · 0.45

Tested by

no test coverage detected