SparseCOOTensor raises error when created with zero elements
- Dominant language
- C++
- Stars
- 17.1k
- Forks
- 4.3k
- Avg merge
- 3d 18h
- Merged PRs (30d)
- 91
Description
Using pyarrow, SparseCOOTensor generates an error when created with zero elements. SparseCSCMatrix and SparseCSRMatrix work fine.
Example:
```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
```
**Environment**: Ubuntu 22, Python 3.10, Pyarrow 9.0.0
**Reporter**: [Bruce Martin](https://issues.apache.org/jira/browse/ARROW-17933)
**Assignee**: [Rok Mihevc](https://issues.apache.org/jira/browse/ARROW-17933) / @rok
**Watchers**: [Rok Mihevc](https://issues.apache.org/jira/browse/ARROW-17933) / @rok
#### PRs and other links:
- [GitHub Pull Request #14378](https://github.com/apache/arrow/pull/14378)
**Note**: *This issue was originally created as [ARROW-17933](https://issues.apache.org/jira/browse/ARROW-17933). Please see the [migration documentation](https://github.com/apache/arrow/issues/14542) for further details.*
Contributor guide
Assessment
This issue has not been assessed yet.