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

Method test_reset_index_drop_convert

xarray/tests/test_dataset.py:3981–4003  ·  view source on GitHub ↗
(
        self,
        arg: str | list[str],
        drop: bool,
        dropped: list[str],
        converted: list[str],
        renamed: dict[str, str],
    )

Source from the content-addressed store, hash-verified

3979 ],
3980 )
3981 def test_reset_index_drop_convert(
3982 self,
3983 arg: str | list[str],
3984 drop: bool,
3985 dropped: list[str],
3986 converted: list[str],
3987 renamed: dict[str, str],
3988 ) -> None:
3989 # regressions https://github.com/pydata/xarray/issues/6946 and
3990 # https://github.com/pydata/xarray/issues/6989
3991 # check that multi-index dimension or level coordinates are dropped, converted
3992 # from IndexVariable to Variable or renamed to dimension as expected
3993 midx = pd.MultiIndex.from_product([["a", "b"], [1, 2]], names=("foo", "bar"))
3994 midx_coords = Coordinates.from_pandas_multiindex(midx, "x")
3995 ds = xr.Dataset(coords=midx_coords)
3996 reset = ds.reset_index(arg, drop=drop)
3997
3998 for name in dropped:
3999 assert name not in reset.variables
4000 for name in converted:
4001 assert_identical(reset[name].variable, ds[name].variable.to_base_variable())
4002 for old_name, new_name in renamed.items():
4003 assert_identical(ds[old_name].variable, reset[new_name].variable)
4004
4005 def test_reorder_levels(self) -> None:
4006 ds = create_test_multiindex()

Callers

nothing calls this directly

Calls 5

reset_indexMethod · 0.95
assert_identicalFunction · 0.90
to_base_variableMethod · 0.80
itemsMethod · 0.80

Tested by

no test coverage detected