MCPcopy Create free account
hub / github.com/pydata/xarray / test_dataset_join

Function test_dataset_join

xarray/tests/test_computation.py:1123–1167  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1121
1122
1123def test_dataset_join() -> None:
1124 ds0 = xr.Dataset({"a": ("x", [1, 2]), "x": [0, 1]})
1125 ds1 = xr.Dataset({"a": ("x", [99, 3]), "x": [1, 2]})
1126
1127 # by default, cannot have different labels
1128 with pytest.raises(ValueError, match=r"cannot align.*join.*exact.*"):
1129 apply_ufunc(operator.add, ds0, ds1)
1130 with pytest.raises(TypeError, match=r"must supply"):
1131 apply_ufunc(operator.add, ds0, ds1, dataset_join="outer")
1132
1133 def add(a, b, join, dataset_join):
1134 return apply_ufunc(
1135 operator.add,
1136 a,
1137 b,
1138 join=join,
1139 dataset_join=dataset_join,
1140 dataset_fill_value=np.nan,
1141 )
1142
1143 actual = add(ds0, ds1, "outer", "inner")
1144 expected = xr.Dataset({"a": ("x", [np.nan, 101, np.nan]), "x": [0, 1, 2]})
1145 assert_identical(actual, expected)
1146
1147 actual = add(ds0, ds1, "outer", "outer")
1148 assert_identical(actual, expected)
1149
1150 with pytest.raises(ValueError, match=r"data variable names"):
1151 apply_ufunc(operator.add, ds0, xr.Dataset({"b": 1}))
1152
1153 ds2 = xr.Dataset({"b": ("x", [99, 3]), "x": [1, 2]})
1154 actual = add(ds0, ds2, "outer", "inner")
1155 expected = xr.Dataset({"x": [0, 1, 2]})
1156 assert_identical(actual, expected)
1157
1158 # we used np.nan as the fill_value in add() above
1159 actual = add(ds0, ds2, "outer", "outer")
1160 expected = xr.Dataset(
1161 {
1162 "a": ("x", [np.nan, np.nan, np.nan]),
1163 "b": ("x", [np.nan, np.nan, np.nan]),
1164 "x": [0, 1, 2],
1165 }
1166 )
1167 assert_identical(actual, expected)
1168
1169
1170@requires_dask

Callers

nothing calls this directly

Calls 3

apply_ufuncFunction · 0.90
addFunction · 0.85
assert_identicalFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…