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

Method test_create_variables

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

Source from the content-addressed store, hash-verified

467 index.unstack()
468
469 def test_create_variables(self) -> None:
470 foo_data = np.array([0, 0, 1], dtype="int64")
471 bar_data = np.array([1.1, 1.2, 1.3], dtype="float64")
472 pd_idx = pd.MultiIndex.from_arrays([foo_data, bar_data], names=("foo", "bar"))
473 index_vars = {
474 "x": IndexVariable("x", pd_idx),
475 "foo": IndexVariable("x", foo_data, attrs={"unit": "m"}),
476 "bar": IndexVariable("x", bar_data, encoding={"fill_value": 0}),
477 }
478
479 index = PandasMultiIndex(pd_idx, "x")
480 actual = index.create_variables(index_vars)
481
482 for k, expected in index_vars.items():
483 assert_identical(actual[k], expected)
484 assert actual[k].dtype == expected.dtype
485 if k != "x":
486 assert actual[k].dtype == index.level_coords_dtype[k]
487
488 def test_sel(self) -> None:
489 index = PandasMultiIndex(

Callers

nothing calls this directly

Calls 5

create_variablesMethod · 0.95
IndexVariableClass · 0.90
PandasMultiIndexClass · 0.90
assert_identicalFunction · 0.90
itemsMethod · 0.80

Tested by

no test coverage detected