MCPcopy Index your code
hub / github.com/pydata/xarray / test_coords_to_index

Method test_coords_to_index

xarray/tests/test_dataarray.py:1570–1593  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1568 self.mda.coords["level_1"] = ("x", np.arange(4))
1569
1570 def test_coords_to_index(self) -> None:
1571 da = DataArray(np.zeros((2, 3)), [("x", [1, 2]), ("y", list("abc"))])
1572
1573 with pytest.raises(ValueError, match=r"no valid index"):
1574 da[0, 0].coords.to_index()
1575
1576 expected = pd.Index(["a", "b", "c"], name="y")
1577 actual = da[0].coords.to_index()
1578 assert expected.equals(actual)
1579
1580 expected = pd.MultiIndex.from_product(
1581 [[1, 2], ["a", "b", "c"]], names=["x", "y"]
1582 )
1583 actual = da.coords.to_index()
1584 assert expected.equals(actual)
1585
1586 expected = pd.MultiIndex.from_product(
1587 [["a", "b", "c"], [1, 2]], names=["y", "x"]
1588 )
1589 actual = da.coords.to_index(["y", "x"])
1590 assert expected.equals(actual)
1591
1592 with pytest.raises(ValueError, match=r"ordered_dims must match"):
1593 da.coords.to_index(["x"])
1594
1595 def test_coord_coords(self) -> None:
1596 orig = DataArray(

Callers

nothing calls this directly

Calls 3

equalsMethod · 0.95
DataArrayClass · 0.90
to_indexMethod · 0.45

Tested by

no test coverage detected