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

Function test_variable_method

xarray/tests/test_sparse.py:226–246  ·  view source on GitHub ↗
(func, sparse_output)

Source from the content-addressed store, hash-verified

224 ids=repr,
225)
226def test_variable_method(func, sparse_output):
227 var_s = make_xrvar({"x": 10, "y": 5})
228 var_d = xr.Variable(var_s.dims, var_s.data.todense())
229 ret_s = func(var_s)
230 ret_d = func(var_d)
231
232 # TODO: figure out how to verify the results of each method
233 if isinstance(ret_d, xr.Variable) and isinstance(ret_d.data, sparse.SparseArray):
234 ret_d = ret_d.copy(data=ret_d.data.todense())
235
236 if sparse_output:
237 assert isinstance(ret_s.data, sparse.SparseArray)
238 assert np.allclose(ret_s.data.todense(), ret_d.data, equal_nan=True)
239 elif func.meth != "to_dict":
240 assert np.allclose(ret_s, ret_d)
241 else:
242 # pop the arrays from the dict
243 arr_s, arr_d = ret_s.pop("data"), ret_d.pop("data")
244
245 assert np.allclose(arr_s, arr_d)
246 assert ret_s == ret_d
247
248
249@pytest.mark.parametrize(

Callers

nothing calls this directly

Calls 4

make_xrvarFunction · 0.85
funcFunction · 0.70
todenseMethod · 0.45
copyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…