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

Method test_constructor

xarray/tests/test_indexes.py:333–355  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

331
332class TestPandasMultiIndex:
333 def test_constructor(self) -> None:
334 foo_data = np.array([0, 0, 1], dtype="int64")
335 bar_data = np.array([1.1, 1.2, 1.3], dtype="float64")
336 pd_idx = pd.MultiIndex.from_arrays([foo_data, bar_data], names=("foo", "bar"))
337
338 index = PandasMultiIndex(pd_idx, "x")
339
340 assert index.dim == "x"
341 assert index.index.equals(pd_idx)
342 assert index.index.names == ("foo", "bar")
343 assert index.index.name == "x"
344 assert index.level_coords_dtype == {
345 "foo": foo_data.dtype,
346 "bar": bar_data.dtype,
347 }
348
349 with pytest.raises(ValueError, match=r".*conflicting multi-index level name.*"):
350 PandasMultiIndex(pd_idx, "foo")
351
352 # default level names
353 pd_idx = pd.MultiIndex.from_arrays([foo_data, bar_data])
354 index = PandasMultiIndex(pd_idx, "x")
355 assert list(index.index.names) == ["x_level_0", "x_level_1"]
356
357 def test_from_variables(self) -> None:
358 v_level1 = xr.Variable(

Callers

nothing calls this directly

Calls 2

PandasMultiIndexClass · 0.90
equalsMethod · 0.45

Tested by

no test coverage detected