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

Method test_reset_index

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

Source from the content-addressed store, hash-verified

3939 assert_identical(actual, expected)
3940
3941 def test_reset_index(self) -> None:
3942 ds = create_test_multiindex()
3943 mindex = ds["x"].to_index()
3944 indexes = [mindex.get_level_values(str(n)) for n in mindex.names]
3945 coords = {idx.name: ("x", idx) for idx in indexes}
3946 expected = Dataset({}, coords=coords)
3947
3948 obj = ds.reset_index("x")
3949 assert_identical(obj, expected, check_default_indexes=False)
3950 assert len(obj.xindexes) == 0
3951
3952 ds = Dataset(coords={"y": ("x", [1, 2, 3])})
3953 with pytest.raises(ValueError, match=r".*not coordinates with an index"):
3954 ds.reset_index("y")
3955
3956 def test_reset_index_keep_attrs(self) -> None:
3957 coord_1 = DataArray([1, 2], dims=["coord_1"], attrs={"attrs": True})

Callers

nothing calls this directly

Calls 5

reset_indexMethod · 0.95
DatasetClass · 0.90
assert_identicalFunction · 0.90
create_test_multiindexFunction · 0.85
to_indexMethod · 0.45

Tested by

no test coverage detected