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

Method test_unstack

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

Source from the content-addressed store, hash-verified

4184 assert list(actual.xindexes) == ["z", "xx", "y"]
4185
4186 def test_unstack(self) -> None:
4187 index = pd.MultiIndex.from_product([[0, 1], ["a", "b"]], names=["x", "y"])
4188 coords = Coordinates.from_pandas_multiindex(index, "z")
4189 ds = Dataset(data_vars={"b": ("z", [0, 1, 2, 3])}, coords=coords)
4190 expected = Dataset(
4191 {"b": (("x", "y"), [[0, 1], [2, 3]]), "x": [0, 1], "y": ["a", "b"]}
4192 )
4193
4194 # check attrs propagated
4195 ds["x"].attrs["foo"] = "bar"
4196 expected["x"].attrs["foo"] = "bar"
4197
4198 for dim in ["z", ["z"], None]:
4199 actual = ds.unstack(dim)
4200 assert_identical(actual, expected)
4201
4202 def test_unstack_errors(self) -> None:
4203 ds = Dataset({"x": [1, 2, 3]})

Callers

nothing calls this directly

Calls 4

unstackMethod · 0.95
DatasetClass · 0.90
assert_identicalFunction · 0.90

Tested by

no test coverage detected