TST Extend tests for scipy.sparse.*array in sklearn/utils/_testing.py#27847
TST Extend tests for scipy.sparse.*array in sklearn/utils/_testing.py#27847y-vectorfield wants to merge 6 commits intoscikit-learn:mainfrom
scipy.sparse.*array in sklearn/utils/_testing.py#27847Conversation
jjerphan
left a comment
There was a problem hiding this comment.
Hi @y-vectorfield,
Thank you for this contribution. The tests can't be run because this file only contains test fixtures.
sklearn/utils/_testing.py
Outdated
| ) | ||
| elif constructor_name == "sparse_csc": | ||
| return sp.sparse.csc_matrix(container, dtype=dtype) | ||
| return csr_container(dtype=dtype) |
There was a problem hiding this comment.
Same suggestions as above but for csc instead of csr.
There was a problem hiding this comment.
I returned the original code.
There was a problem hiding this comment.
| return csr_container(dtype=dtype) | |
| return sp.sparse.csc_matrix(container, dtype=dtype) |
sklearn/utils/_testing.py
Outdated
| os.unlink(source_file) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("csr_container", CSR_CONTAINERS) |
There was a problem hiding this comment.
This is a fixture, not a test, so it need not be parametrized.
| @pytest.mark.parametrize("csr_container", CSR_CONTAINERS) |
| @@ -781,15 +783,15 @@ def _convert_container( | |||
| elif constructor_name == "slice": | |||
| return slice(container[0], container[1]) | |||
| elif constructor_name == "sparse_csr": | |||
There was a problem hiding this comment.
| elif constructor_name == "sparse_csr": | |
| elif constructor_name == "sparse_csr": | |
| # TODO: when we depend on SciPy>=1.8 return `csr_array` instead and change | |
| # the case bellow from `sparse_csr_array` to `sparse_csr_matrix` and make | |
| # it return a `csr_matrix`. |
There was a problem hiding this comment.
I added your suggestion to the source file.
sklearn/utils/_testing.py
Outdated
| return slice(container[0], container[1]) | ||
| elif constructor_name == "sparse_csr": | ||
| return sp.sparse.csr_matrix(container, dtype=dtype) | ||
| return csr_container(dtype=dtype) |
There was a problem hiding this comment.
| return csr_container(dtype=dtype) | |
| return sp.sparse.csr_matrix(container, dtype=dtype) |
There was a problem hiding this comment.
I also returned the original code.
sklearn/utils/_testing.py
Outdated
| ) | ||
| from sklearn.utils._array_api import _check_array_api_dispatch | ||
| from sklearn.utils.fixes import parse_version, sp_version | ||
| from sklearn.utils.fixes import CSR_CONTAINERS, parse_version, sp_version |
There was a problem hiding this comment.
This is not needed anymore.
| from sklearn.utils.fixes import CSR_CONTAINERS, parse_version, sp_version | |
| from sklearn.utils.fixes import parse_version, sp_version |
There was a problem hiding this comment.
I also removed this module import.
|
@jjerphan, thank you very much for your comments. |
0f4abb3 to
1d45c34
Compare
|
I have added a few suggestions in my review above to show what needs to be modified. |
Oh, sorry, I will be careful not to force push in the future. |
It's fine. :) I will review the PR once the failures on the CI are fixed. Let me know if you need help. |
Hello, @jjerphan, thank you very much for your message. |
sklearn/utils/_testing.py
Outdated
| ) | ||
| elif constructor_name == "sparse_csc": | ||
| return sp.sparse.csc_matrix(container, dtype=dtype) | ||
| return csr_container(dtype=dtype) |
There was a problem hiding this comment.
This needs to be changed as suggested above.
There was a problem hiding this comment.
Hello, @jjerphan,
Oh, I'm sorry. Do you mean as follows??
current version
return csr_container(dtype=dtype)modified version(I will add.)
return csc_container(dtype=dtype)There was a problem hiding this comment.
The current version of source is as follow,
https://github.com/y-vectorfield/scikit-learn/blob/1d45c34d1f2706fbdd5599644f317e4a3a34934f/sklearn/utils/_testing.py#L761C1-L788C60
There was a problem hiding this comment.
I meant #27847 (comment) and #27847 (comment) but for CSC.
There was a problem hiding this comment.
@jjerphan, I'm sorry for the confusion.
I modified the source.
jjerphan
left a comment
There was a problem hiding this comment.
What I meant is shown by those suggestions.
sklearn/utils/_testing.py
Outdated
| elif constructor_name == "sparse_csr_array": | ||
| if sp_version >= parse_version("1.8"): | ||
| return sp.sparse.csr_array(container, dtype=dtype) | ||
| return sp.sparse.csc_array(container, dtype=dtype) |
There was a problem hiding this comment.
| return sp.sparse.csc_array(container, dtype=dtype) | |
| return sp.sparse.csr_array(container, dtype=dtype) |
There was a problem hiding this comment.
@jjerphan ,
Oh, I'm sorry. I reflected your comment.
| raise ValueError( | ||
| f"sparse_csr_array is only available with scipy>=1.8.0, got {sp_version}" | ||
| ) | ||
| elif constructor_name == "sparse_csc": |
There was a problem hiding this comment.
| elif constructor_name == "sparse_csc": | |
| elif constructor_name == "sparse_csc": | |
| # TODO: when we depend on SciPy>=1.8 return `csc_array` instead and change | |
| # the case bellow from `sparse_csc_array` to `sparse_csc_matrix` and make | |
| # it return a `csc_matrix`. |
sklearn/utils/_testing.py
Outdated
| ) | ||
| elif constructor_name == "sparse_csc": | ||
| return sp.sparse.csc_matrix(container, dtype=dtype) | ||
| return csr_container(dtype=dtype) |
There was a problem hiding this comment.
| return csr_container(dtype=dtype) | |
| return sp.sparse.csc_matrix(container, dtype=dtype) |
|
@y-vectorfield: are you still interested in working on this PR? |
Hello, @jjerphan, thank you for your message. |
|
Hi @y-vectorfield would you like to continue working on this PR? Let us know if you need help. |
|
Hello, @marenwestermann , very sorry. I've been away from this task for a while. |
|
@jjerphan , @marenwestermann , |
|
@jjerphan , @marenwestermann , |
|
I didn't get what this PR intends to do. It seems that on |
|
There are still a couple of adaption left for sparse array and sparse matrices. I do not have time to sort this out, but it should be trivial. Can someone have a look at the merge conflicts, please? |
|
scikit-learn/sklearn/utils/_testing.py Lines 815 to 836 in f323eb4 The problem is that I tried to resolve the merge conflicts but then no relevant changes are left. As above we already have csc and csr arrays and matrices on main, and this PR does not seem to involve anything beyond that. Or should it? |
|
OK, so then let's close it. |
|
@jjerphan , thank you very much for your review. |
Towards #27090.