rok commented on code in PR #50907:
URL: https://github.com/apache/arrow/pull/50907#discussion_r3845932023


##########
python/pyarrow/tests/test_sparse_tensor.py:
##########
@@ -254,6 +254,36 @@ def test_sparse_csr_matrix_from_dense(dtype_str, 
arrow_type):
     assert np.array_equal(indices, result_indices)
 
 
+def test_sparse_csr_matrix_from_1d():
+    array = np.array([1, 0, 2, 0, 0, 3, 0, 4], dtype=np.int64)
+    tensor = pa.Tensor.from_numpy(array)
+
+    sparse = pa.SparseCSRMatrix.from_dense_numpy(array)
+    assert sparse.shape == (1, 8)
+    assert sparse.non_zero_length == 4
+
+    sparse = pa.SparseCSRMatrix.from_tensor(tensor)
+    assert sparse.shape == (1, 8)
+    assert sparse.non_zero_length == 4
+
+    dense = sparse.to_tensor()
+    assert dense.shape == (1, 8)
+    assert np.array_equal(np.array(dense).ravel(), array)
+
+
+def test_sparse_csc_matrix_from_1d():
+    array = np.array([1, 0, 2, 0, 0, 3, 0, 4], dtype=np.int64)
+    tensor = pa.Tensor.from_numpy(array)
+
+    sparse = pa.SparseCSCMatrix.from_dense_numpy(array)
+    assert sparse.shape == (1, 8)
+    assert sparse.non_zero_length == 4
+
+    sparse = pa.SparseCSCMatrix.from_tensor(tensor)
+    assert sparse.shape == (1, 8)
+    assert sparse.non_zero_length == 4

Review Comment:
   Please make these parametric so they can be expressed as a single test and 
compare pyarrow's behavior to scipy's.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to