MCPcopy Index your code
hub / github.com/pydata/xarray / test_unstack_fill_value

Method test_unstack_fill_value

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

Source from the content-addressed store, hash-verified

4218 ds.unstack("x")
4219
4220 def test_unstack_fill_value(self) -> None:
4221 ds = xr.Dataset(
4222 {"var": (("x",), np.arange(6)), "other_var": (("x",), np.arange(3, 9))},
4223 coords={"x": [0, 1, 2] * 2, "y": (("x",), ["a"] * 3 + ["b"] * 3)},
4224 )
4225 # make ds incomplete
4226 ds = ds.isel(x=[0, 2, 3, 4]).set_index(index=["x", "y"])
4227 # test fill_value
4228 actual1 = ds.unstack("index", fill_value=-1)
4229 expected1 = ds.unstack("index").fillna(-1).astype(int)
4230 assert actual1["var"].dtype == int
4231 assert_equal(actual1, expected1)
4232
4233 actual2 = ds["var"].unstack("index", fill_value=-1)
4234 expected2 = ds["var"].unstack("index").fillna(-1).astype(int)
4235 assert_equal(actual2, expected2)
4236
4237 actual3 = ds.unstack("index", fill_value={"var": -1, "other_var": 1})
4238 expected3 = ds.unstack("index").fillna({"var": -1, "other_var": 1}).astype(int)
4239 assert_equal(actual3, expected3)
4240
4241 actual4 = ds.unstack("index", fill_value={"var": -1})
4242 expected4 = ds.unstack("index").fillna({"var": -1, "other_var": np.nan})
4243 assert_equal(actual4, expected4)
4244
4245 @requires_sparse
4246 def test_unstack_sparse(self) -> None:

Callers

nothing calls this directly

Calls 8

iselMethod · 0.95
unstackMethod · 0.95
assert_equalFunction · 0.90
arangeMethod · 0.80
set_indexMethod · 0.45
astypeMethod · 0.45
fillnaMethod · 0.45
unstackMethod · 0.45

Tested by

no test coverage detected