MCPcopy Create free account
hub / github.com/apache/arrow / test_dense_to_sparse_tensor

Function test_dense_to_sparse_tensor

python/pyarrow/tests/test_sparse_tensor.py:386–401  ·  view source on GitHub ↗
(dtype_str, arrow_type, sparse_tensor_type)

Source from the content-addressed store, hash-verified

384])
385@pytest.mark.parametrize('dtype_str,arrow_type', tensor_type_pairs)
386def test_dense_to_sparse_tensor(dtype_str, arrow_type, sparse_tensor_type):
387 dtype = np.dtype(dtype_str)
388 array = np.array([[4, 0, 9, 0],
389 [0, 7, 0, 0],
390 [0, 0, 0, 0],
391 [0, 0, 0, 5]]).astype(dtype)
392 dim_names = ('x', 'y')
393
394 sparse_tensor = sparse_tensor_type.from_dense_numpy(array, dim_names)
395 tensor = sparse_tensor.to_tensor()
396 result_array = tensor.to_numpy()
397
398 assert sparse_tensor.type == arrow_type
399 assert tensor.type == arrow_type
400 assert sparse_tensor.dim_names == dim_names
401 assert np.array_equal(array, result_array)
402
403
404@pytest.mark.skipif(not coo_matrix, reason="requires scipy")

Callers

nothing calls this directly

Calls 2

dtypeMethod · 0.80
arrayMethod · 0.45

Tested by

no test coverage detected