Skip to content

GH-45229: [Python] Migrate from scipy.spmatrix to scipy.sparray #46423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rok
Copy link
Member

@rok rok commented May 13, 2025

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 only scipy.spmatrix) objects and test for it.

What changes are included in this PR?

This adjusts pa.SparseCXXMatrix constructors and pa.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 and pyarrow.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 take scipy.sparray and scipy.spmatrix which would not be a breaking change.

@rok rok force-pushed the gh-45229-scipy-sparse-xxx_array-migration branch 2 times, most recently from 7d08c0b to 475eecf Compare May 13, 2025 11:24
@rok rok force-pushed the gh-45229-scipy-sparse-xxx_array-migration branch from 475eecf to 1ead380 Compare May 13, 2025 14:56
@rok rok marked this pull request as ready for review May 13, 2025 16:15
@rok rok requested review from AlenkaF and raulcd as code owners May 13, 2025 16:15
@rok
Copy link
Member Author

rok commented May 13, 2025

@TheNeuralBit does this look ok to you?

Copy link
Member

@TheNeuralBit TheNeuralBit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This generally looks fine to me. It could be nice to document the potentially breaking change, but I don't think we have a way to do that.

Another thing to consider is version compatibility. It looks like the sparse arrays were added in scipy 1.8.0 so that would be a new lower bound. Again I'm not sure if we have a way to document this

@rok
Copy link
Member Author

rok commented May 14, 2025

Another thing to consider is version compatibility. It looks like the sparse arrays were added in scipy 1.8.0 so that would be a new lower bound. Again I'm not sure if we have a way to document this

That's a good point. I suppose we should check for scipy version when returning from to_scipy .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants