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

Method test_categorical_index

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

Source from the content-addressed store, hash-verified

1885 ds.sel(ind="bar", tolerance="nearest") # type: ignore[arg-type]
1886
1887 def test_categorical_index(self) -> None:
1888 cat = pd.CategoricalIndex(
1889 ["foo", "bar", "foo"],
1890 categories=["foo", "bar", "baz", "qux", "quux", "corge"],
1891 )
1892 ds = xr.Dataset(
1893 {"var": ("cat", np.arange(3))},
1894 coords={"cat": ("cat", cat), "c": ("cat", [0, 1, 1])},
1895 )
1896 # test slice
1897 actual1 = ds.sel(cat="foo")
1898 expected1 = ds.isel(cat=[0, 2])
1899 assert_identical(expected1, actual1)
1900 # make sure the conversion to the array works
1901 actual2 = ds.sel(cat="foo")["cat"].values
1902 assert (actual2 == np.array(["foo", "foo"])).all()
1903
1904 ds = ds.set_index(index=["cat", "c"])
1905 actual3 = ds.unstack("index")
1906 assert actual3["var"].shape == (2, 2)
1907
1908 def test_categorical_index_reindex(self) -> None:
1909 cat = pd.CategoricalIndex(

Callers

nothing calls this directly

Calls 7

selMethod · 0.95
iselMethod · 0.95
set_indexMethod · 0.95
unstackMethod · 0.95
assert_identicalFunction · 0.90
arangeMethod · 0.80
allMethod · 0.45

Tested by

no test coverage detected