-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
MAINT Use scipy.sparse.isspmatrix_*
#26420
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
MAINT Use scipy.sparse.isspmatrix_*
#26420
Conversation
Signed-off-by: Julien Jerphanion <git@jjerphan.xyz>
scipy.sparse.isspmatrix_*
@rossbar: FYI, this is the PR that intentionally uses the current behavior of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. It's a bit unfortunate that the name is isspmatrix
.
Based on IRL discussions with @rossbar, similar |
There's still discussion to be had, but I would propose to deprecate the Instead of e.g.
The worst case is when you want to ensure that the input is a sparse array and not a sparse matrix. For this case I think the only current way to do it is with three independent checks: one for sparsity, one to ensure it's not a matrix, and a final one for the format: >>> issparse(a) and not isinstance(a, spmatrix) and a.format == "csc" |
Let's wait for scipy/scipy#18528 to be merged before pursuing. |
Another update here - after scipy/scipy#18531, |
Yes, this PR needs to be updated to use |
I would be in favor of merging this PR for uniformity and addressing the conversion in another PR. What do you think? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Reference Issues/PRs
Towards resolving #26418.
What does this implement/fix? Explain your changes.
Contrary to what names suggest,
scipy.sparse.isspmatrix_*
not only check for sparse matrices' instances but also sparse arrays'.This PR proposes replacing all occurrences of checks using
isinstance(X, *_matrix)
by checks calling toscipy.sparse.isspmatrix_*
.Any other comments?
Later, when$n$ -dimensional arrays are implemented (with $n > 2$ ) in SciPy, we will need to add extra checks on $n$ .
cc @ivirshup