Skip to content
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

BUG: sparse.csgraph, array types: support non-zero fill_values #20773

Merged
merged 7 commits into from
May 29, 2024

Conversation

mtsokol
Copy link
Contributor

@mtsokol mtsokol commented May 23, 2024

Connected to: #20763, pydata/sparse#685, finch-tensor/finch-tensor-python#59

Hi @hameerabbasi,

This PR allows to pass pydata/sparse arrays with np.inf fill-values to the selected scipy.sparse.csgraph functions.

@github-actions github-actions bot added scipy.sparse scipy.sparse.csgraph Cython Issues with the internal Cython code base labels May 23, 2024
@mtsokol
Copy link
Contributor Author

mtsokol commented May 23, 2024

I think once pydata/sparse maintenance release is made then CI should be green.

@lucascolley lucascolley added the array types Items related to array API support and input array validation (see gh-18286) label May 23, 2024
@lucascolley lucascolley changed the title pydata/sparse: Support fill_values in csgraph BUG: sparse.csgraph, array types: support fill_values in csgraph May 23, 2024
@lucascolley lucascolley changed the title BUG: sparse.csgraph, array types: support fill_values in csgraph BUG: sparse.csgraph, array types: support non-zero fill_values May 23, 2024
@lucascolley lucascolley added the defect A clear bug or issue that prevents SciPy from being installed or used as expected label May 23, 2024
@hameerabbasi
Copy link
Contributor

The tests at scipy/sparse/csgraph/tests/test_pydata_sparse.py might need adjusting -- maintainence release is up on PyPI: https://pypi.org/project/sparse/0.15.4/

@mtsokol mtsokol requested a review from hameerabbasi May 24, 2024 08:58
Copy link
Contributor

@hameerabbasi hameerabbasi left a comment

Choose a reason for hiding this comment

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

Thanks for the work on this @mtsokol!

Copy link
Member

@rgommers rgommers left a comment

Choose a reason for hiding this comment

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

The test and changes LGTM, except for relying on a feature that is brand new in pydata sparse. How about wrapping the to_scipy_sparse(accept_fv) call in a try-except, catching the TypeError and then callign again without use of accept_fv? That keeps the default behavior with 0 fill value supported for older versions.

scipy/sparse/_sputils.py Outdated Show resolved Hide resolved
Copy link
Contributor

@hameerabbasi hameerabbasi left a comment

Choose a reason for hiding this comment

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

A few more places where a new sparse version is required.

scipy/sparse/csgraph/_tools.pyx Outdated Show resolved Hide resolved
scipy/sparse/csgraph/_validation.py Show resolved Hide resolved
@mtsokol mtsokol requested a review from hameerabbasi May 27, 2024 10:56
Copy link
Contributor

@hameerabbasi hameerabbasi left a comment

Choose a reason for hiding this comment

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

Thanks for all the hard work here @mtsokol!

scipy/sparse/csgraph/tests/test_pydata_sparse.py Outdated Show resolved Hide resolved
Co-authored-by: Hameer Abbasi <2190658+hameerabbasi@users.noreply.github.com>
@rgommers
Copy link
Member

Some comments above each try-except would be useful. I suggest:

# The `accept_fv` keyword is new in PyData Sparse 0.15.4 (May 2024),
# remove the `except` once the minimum supported version is >=0.15.4

@mtsokol
Copy link
Contributor Author

mtsokol commented May 29, 2024

Sure! I added comments.

@mtsokol mtsokol requested a review from rgommers May 29, 2024 09:16
Copy link
Member

@rgommers rgommers left a comment

Choose a reason for hiding this comment

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

LGTM now, let's give this a go. Thanks @mtsokol, and thanks @hameerabbasi for the reviews.

@rgommers rgommers merged commit 74c13e4 into scipy:main May 29, 2024
29 of 31 checks passed
@WarrenWeckesser
Copy link
Member

It looks like the new code doesn't handle sparse versions before 0.15.4 correctly: #20861

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
array types Items related to array API support and input array validation (see gh-18286) Cython Issues with the internal Cython code base defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.sparse.csgraph scipy.sparse
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants