GH-45229: [Python] Migrate from scipy.spmatrix to scipy.sparray #46423
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Rationale for this change
As per SciPy's migration guide it would be good to change the constructors we use when creating scipy's sparse object. Further we should allow for creating sparse arrow objects from
scipy.sparray
(currently onlyscipy.spmatrix)
objects and test for it.What changes are included in this PR?
This adjusts
pa.SparseCXXMatrix
constructors andpa.SparseCXXMatrix.to_scipy
to achieve goals listed above and adds tests.Are these changes tested?
Yes.
Are there any user-facing changes?
pyarrow.coo_matrix.to_scipy
andpyarrow.csr_matrix.to_scipy
would now return different types (sparray instead of spmatrix) which would probably be a breaking change (behaviors of the types would be similar).Additionally
pa.SparseCXXMatrix.from_scipy
would now takescipy.sparray
andscipy.spmatrix
which would not be a breaking change.