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

Method test_from_sparse

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

Source from the content-addressed store, hash-verified

7557
7558 @requires_sparse
7559 def test_from_sparse(self) -> None:
7560 import sparse
7561
7562 arr = np.diagflat([1, 2, 3])
7563 sparr = sparse.COO.from_numpy(arr)
7564 da = xr.DataArray(
7565 sparr, dims=["x", "y"], coords={"elev": (("x", "y"), sparr + 3)}
7566 )
7567
7568 expected = xr.DataArray(
7569 arr, dims=["x", "y"], coords={"elev": (("x", "y"), arr + 3)}
7570 )
7571 assert_identical(da.as_numpy(), expected)
7572 np.testing.assert_equal(da.to_numpy(), arr)
7573
7574 @requires_cupy
7575 def test_from_cupy(self) -> None:

Callers

nothing calls this directly

Calls 3

as_numpyMethod · 0.95
to_numpyMethod · 0.95
assert_identicalFunction · 0.90

Tested by

no test coverage detected