This is an automated email from the ASF dual-hosted git repository.

raulcd pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/main by this push:
     new 292e460de0 GH-45229: [Python] skip scipy.sparse roundtrip tests for 
float16 (#46413)
292e460de0 is described below

commit 292e460de0b941fcfb934a62d0d222f257e9a312
Author: Brian Hulette <[email protected]>
AuthorDate: Thu May 15 01:12:45 2025 -0700

    GH-45229: [Python] skip scipy.sparse roundtrip tests for float16 (#46413)
    
    ### Rationale for this change
    
    float16 has never been truly supported in `scipy.sparse`, and it is 
explicitly rejected now in the 1.15 release 
(https://github.com/scipy/scipy/issues/20207).
    
    ### What changes are included in this PR?
    
    Skip tests that roundtrip arrow float16 sparse tensors through scipy.sparse 
csr and coo matrices.
    
    * GitHub Issue: #45229
    
    Authored-by: Brian Hulette <[email protected]>
    Signed-off-by: Raúl Cumplido <[email protected]>
---
 python/pyarrow/tests/test_sparse_tensor.py | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/python/pyarrow/tests/test_sparse_tensor.py 
b/python/pyarrow/tests/test_sparse_tensor.py
index 7ba9e2b3e1..6cd3d2c41e 100644
--- a/python/pyarrow/tests/test_sparse_tensor.py
+++ b/python/pyarrow/tests/test_sparse_tensor.py
@@ -51,6 +51,11 @@ tensor_type_pairs = [
     ('f8', pa.float64())
 ]
 
+# scipy.sparse does not support float16
+scipy_type_pairs = [
+    pair for pair in tensor_type_pairs if pair[0] != 'f2'
+]
+
 
 @pytest.mark.parametrize('sparse_tensor_type', [
     pa.SparseCSRMatrix,
@@ -395,7 +400,7 @@ def test_dense_to_sparse_tensor(dtype_str, arrow_type, 
sparse_tensor_type):
 
 
 @pytest.mark.skipif(not coo_matrix, reason="requires scipy")
[email protected]('dtype_str,arrow_type', tensor_type_pairs)
[email protected]('dtype_str,arrow_type', scipy_type_pairs)
 def test_sparse_coo_tensor_scipy_roundtrip(dtype_str, arrow_type):
     dtype = np.dtype(dtype_str)
     data = np.array([1, 2, 3, 4, 5, 6]).astype(dtype)
@@ -420,11 +425,7 @@ def test_sparse_coo_tensor_scipy_roundtrip(dtype_str, 
arrow_type):
     assert np.array_equal(scipy_matrix.row, out_scipy_matrix.row)
     assert np.array_equal(scipy_matrix.col, out_scipy_matrix.col)
 
-    if dtype_str == 'f2':
-        dense_array = \
-            scipy_matrix.astype(np.float32).toarray().astype(np.float16)
-    else:
-        dense_array = scipy_matrix.toarray()
+    dense_array = scipy_matrix.toarray()
     assert np.array_equal(dense_array, sparse_tensor.to_tensor().to_numpy())
 
     # canonical sparse coo matrix
@@ -439,7 +440,7 @@ def test_sparse_coo_tensor_scipy_roundtrip(dtype_str, 
arrow_type):
 
 
 @pytest.mark.skipif(not csr_matrix, reason="requires scipy")
[email protected]('dtype_str,arrow_type', tensor_type_pairs)
[email protected]('dtype_str,arrow_type', scipy_type_pairs)
 def test_sparse_csr_matrix_scipy_roundtrip(dtype_str, arrow_type):
     dtype = np.dtype(dtype_str)
     data = np.array([8, 2, 5, 3, 4, 6]).astype(dtype)
@@ -460,11 +461,7 @@ def test_sparse_csr_matrix_scipy_roundtrip(dtype_str, 
arrow_type):
     assert np.array_equal(sparse_array.indptr, out_sparse_array.indptr)
     assert np.array_equal(sparse_array.indices, out_sparse_array.indices)
 
-    if dtype_str == 'f2':
-        dense_array = \
-            sparse_array.astype(np.float32).toarray().astype(np.float16)
-    else:
-        dense_array = sparse_array.toarray()
+    dense_array = sparse_array.toarray()
     assert np.array_equal(dense_array, sparse_tensor.to_tensor().to_numpy())
 
 

Reply via email to