(self)
| 4080 | assert indexed.xindexes["foo"].opt == 1 # type: ignore[attr-defined] |
| 4081 | |
| 4082 | def test_stack(self) -> None: |
| 4083 | ds = Dataset( |
| 4084 | data_vars={"b": (("x", "y"), [[0, 1], [2, 3]])}, |
| 4085 | coords={"x": ("x", [0, 1]), "y": ["a", "b"]}, |
| 4086 | ) |
| 4087 | |
| 4088 | midx_expected = pd.MultiIndex.from_product( |
| 4089 | [[0, 1], ["a", "b"]], names=["x", "y"] |
| 4090 | ) |
| 4091 | midx_coords_expected = Coordinates.from_pandas_multiindex(midx_expected, "z") |
| 4092 | expected = Dataset( |
| 4093 | data_vars={"b": ("z", [0, 1, 2, 3])}, coords=midx_coords_expected |
| 4094 | ) |
| 4095 | # check attrs propagated |
| 4096 | ds["x"].attrs["foo"] = "bar" |
| 4097 | expected["x"].attrs["foo"] = "bar" |
| 4098 | |
| 4099 | actual = ds.stack(z=["x", "y"]) |
| 4100 | assert_identical(expected, actual) |
| 4101 | assert list(actual.xindexes) == ["z", "x", "y"] |
| 4102 | |
| 4103 | actual = ds.stack(z=[...]) |
| 4104 | assert_identical(expected, actual) |
| 4105 | |
| 4106 | # non list dims with ellipsis |
| 4107 | actual = ds.stack(z=(...,)) |
| 4108 | assert_identical(expected, actual) |
| 4109 | |
| 4110 | # ellipsis with given dim |
| 4111 | actual = ds.stack(z=[..., "y"]) |
| 4112 | assert_identical(expected, actual) |
| 4113 | |
| 4114 | midx_expected = pd.MultiIndex.from_product( |
| 4115 | [["a", "b"], [0, 1]], names=["y", "x"] |
| 4116 | ) |
| 4117 | midx_coords_expected = Coordinates.from_pandas_multiindex(midx_expected, "z") |
| 4118 | expected = Dataset( |
| 4119 | data_vars={"b": ("z", [0, 2, 1, 3])}, coords=midx_coords_expected |
| 4120 | ) |
| 4121 | expected["x"].attrs["foo"] = "bar" |
| 4122 | |
| 4123 | actual = ds.stack(z=["y", "x"]) |
| 4124 | assert_identical(expected, actual) |
| 4125 | assert list(actual.xindexes) == ["z", "y", "x"] |
| 4126 | |
| 4127 | @pytest.mark.parametrize( |
| 4128 | "create_index,expected_keys", |
nothing calls this directly
no test coverage detected