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

Method test_from_sparse

xarray/tests/test_variable.py:3115–3127  ·  view source on GitHub ↗
(self, Var)

Source from the content-addressed store, hash-verified

3113
3114 @requires_sparse
3115 def test_from_sparse(self, Var):
3116 if Var is IndexVariable:
3117 pytest.skip("Can't have 2D IndexVariables")
3118
3119 import sparse
3120
3121 arr = np.diagflat([1, 2, 3])
3122 coords = np.array([[0, 1, 2], [0, 1, 2]])
3123 sparr = sparse.COO(coords=coords, data=[1, 2, 3], shape=(3, 3))
3124 v = Variable(["x", "y"], sparr)
3125
3126 assert_identical(v.as_numpy(), Variable(["x", "y"], arr))
3127 np.testing.assert_equal(v.to_numpy(), arr)
3128
3129 @requires_cupy
3130 def test_from_cupy(self, Var):

Callers

nothing calls this directly

Calls 4

VariableClass · 0.90
assert_identicalFunction · 0.90
as_numpyMethod · 0.45
to_numpyMethod · 0.45

Tested by

no test coverage detected