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

Method test_stack_non_dim_coords

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

Source from the content-addressed store, hash-verified

4170 ds.stack(z=["x", "y"], create_index=True)
4171
4172 def test_stack_non_dim_coords(self) -> None:
4173 ds = Dataset(
4174 data_vars={"b": (("x", "y"), [[0, 1], [2, 3]])},
4175 coords={"x": ("x", [0, 1]), "y": ["a", "b"]},
4176 ).rename_vars(x="xx")
4177
4178 exp_index = pd.MultiIndex.from_product([[0, 1], ["a", "b"]], names=["xx", "y"])
4179 exp_coords = Coordinates.from_pandas_multiindex(exp_index, "z")
4180 expected = Dataset(data_vars={"b": ("z", [0, 1, 2, 3])}, coords=exp_coords)
4181
4182 actual = ds.stack(z=["x", "y"])
4183 assert_identical(expected, actual)
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"])

Callers

nothing calls this directly

Calls 5

DatasetClass · 0.90
assert_identicalFunction · 0.90
rename_varsMethod · 0.45
stackMethod · 0.45

Tested by

no test coverage detected