[ 
https://issues.apache.org/jira/browse/ARROW-17933?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17655731#comment-17655731
 ] 

Bruce Martin commented on ARROW-17933:
--------------------------------------

In case it is helpful, I have also found that there is differences in behavior 
between Python versions. It fails as above on Python 3.8 and 3.9, but works on 
3.7.

Python 3.7:

```python
In [6]: import sys, numpy as np, pyarrow as pa
In [7]: sys.version
Out[7]: '3.7.16 (default, Dec  7 2022, 01:12:19) \n[GCC 9.4.0]'
In [8]: np.__version__
Out[8]: '1.21.6'
In [9]: pa.__version__
Out[9]: '10.0.1'
In [10]: pa.SparseCOOTensor.from_numpy(np.array([], dtype=np.uint16), 
[np.array([],dtype=np.int64), np.array([],dtype=np.int64)], shape=(10, 100))
Out[10]: 
<pyarrow.SparseCOOTensor>
type: uint16
shape: (10, 100)
```

Python 3.9:

```python
In [1]: import sys, numpy as np, pyarrow as pa
In [2]: sys.version
Out[2]: '3.9.16 (main, Dec  7 2022, 01:11:51) \n[GCC 9.4.0]'
In [3]: np.__version__
Out[3]: '1.23.5'
In [4]: pa.__version__
Out[4]: '10.0.1'
In [5]: pa.SparseCOOTensor.from_numpy(np.array([], dtype=np.uint16), 
[np.array([],dtype=np.int64), np.array([],dtype=np.int64)], shape=(10, 100))
---------------------------------------------------------------------------
ArrowInvalid                              Traceback (most recent call last)
Cell In [5], line 1
----> 1 pa.SparseCOOTensor.from_numpy(np.array([], dtype=np.uint16), 
[np.array([],dtype=np.int64), np.array([],dtype=np.int64)], shape=(10, 100))
File ~/TileDB-SOMA/venv/lib/python3.9/site-packages/pyarrow/tensor.pxi:354, in 
pyarrow.lib.SparseCOOTensor.from_numpy()
File ~/TileDB-SOMA/venv/lib/python3.9/site-packages/pyarrow/error.pxi:100, in 
pyarrow.lib.check_status()
ArrowInvalid: SparseCOOIndex indices must be contiguous
```

> SparseCOOTensor raises error when created with zero elements
> ------------------------------------------------------------
>
>                 Key: ARROW-17933
>                 URL: https://issues.apache.org/jira/browse/ARROW-17933
>             Project: Apache Arrow
>          Issue Type: Bug
>          Components: Python
>    Affects Versions: 9.0.0
>         Environment: Ubuntu 22, Python 3.10, Pyarrow 9.0.0
>            Reporter: Bruce Martin
>            Assignee: Rok Mihevc
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 2h 10m
>  Remaining Estimate: 0h
>
> Using pyarrow, SparseCOOTensor generates an error when created with zero 
> elements. SparseCSCMatrix and SparseCSRMatrix work fine.
> Example:
> {code:java}
> In [24]: pyarrow._version_
> Out[24]: '9.0.0'
> In [25]: 
> pyarrow.SparseCSCMatrix.from_scipy(scipy.sparse.csc_matrix(numpy.zeros((2,4)),
>  dtype=numpy.float32)).non_zero_length
> Out[25]: 0
> In [26]: 
> pyarrow.SparseCSRMatrix.from_scipy(scipy.sparse.csr_matrix(numpy.zeros((2,4)),
>  dtype=numpy.float32)).non_zero_length
> Out[26]: 0
> In [27]: 
> pyarrow.SparseCOOTensor.from_scipy(scipy.sparse.coo_matrix(numpy.zeros((2,4)),
>  dtype=numpy.float32)).non_zero_length
> ---------------------------------------------------------------------------
> ArrowInvalid Traceback (most recent call last)
> Cell In [27], line 1
> ----> 1 
> pyarrow.SparseCOOTensor.from_scipy(scipy.sparse.coo_matrix(numpy.zeros((2,4)),
>  dtype=numpy.float32)).non_zero_length
> File ~/venv/lib/python3.10/site-packages/pyarrow/tensor.pxi:400, in 
> pyarrow.lib.SparseCOOTensor.from_scipy()
> File ~/venv/lib/python3.10/site-packages/pyarrow/error.pxi:100, in 
> pyarrow.lib.check_status()
> ArrowInvalid: SparseCOOIndex indices must be contiguous
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to