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

Method test_from_sparse

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

Source from the content-addressed store, hash-verified

8343
8344 @requires_sparse
8345 def test_from_sparse(self) -> None:
8346 import sparse
8347
8348 arr = np.diagflat([1, 2, 3])
8349 sparr = sparse.COO.from_numpy(arr)
8350 ds = xr.Dataset(
8351 {"a": (["x", "y"], sparr)}, coords={"elev": (("x", "y"), sparr + 3)}
8352 )
8353
8354 expected = xr.Dataset(
8355 {"a": (["x", "y"], arr)}, coords={"elev": (("x", "y"), arr + 3)}
8356 )
8357 assert_identical(ds.as_numpy(), expected)
8358
8359 @requires_cupy
8360 def test_from_cupy(self) -> None:

Callers

nothing calls this directly

Calls 2

as_numpyMethod · 0.95
assert_identicalFunction · 0.90

Tested by

no test coverage detected