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

Method test_set_index_deindexed_coords

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

Source from the content-addressed store, hash-verified

3915 ds.set_index(x="x")
3916
3917 def test_set_index_deindexed_coords(self) -> None:
3918 # test de-indexed coordinates are converted to base variable
3919 # https://github.com/pydata/xarray/issues/6969
3920 one = ["a", "a", "b", "b"]
3921 two = [1, 2, 1, 2]
3922 three = ["c", "c", "d", "d"]
3923 four = [3, 4, 3, 4]
3924
3925 midx_12 = pd.MultiIndex.from_arrays([one, two], names=["one", "two"])
3926 midx_34 = pd.MultiIndex.from_arrays([three, four], names=["three", "four"])
3927
3928 coords = Coordinates.from_pandas_multiindex(midx_12, "x")
3929 coords["three"] = ("x", three)
3930 coords["four"] = ("x", four)
3931 ds = xr.Dataset(coords=coords)
3932 actual = ds.set_index(x=["three", "four"])
3933
3934 coords_expected = Coordinates.from_pandas_multiindex(midx_34, "x")
3935 coords_expected["one"] = ("x", one)
3936 coords_expected["two"] = ("x", two)
3937 expected = xr.Dataset(coords=coords_expected)
3938
3939 assert_identical(actual, expected)
3940
3941 def test_reset_index(self) -> None:
3942 ds = create_test_multiindex()

Callers

nothing calls this directly

Calls 3

set_indexMethod · 0.95
assert_identicalFunction · 0.90

Tested by

no test coverage detected