Skip to content

convert sparse matrix into sparse container (TST Extend tests for scipy.sparse.*array ) - #28456

Closed
wmin401 wants to merge 1 commit into
scikit-learn:mainfrom
wmin401:fix-27682
Closed

wmin401 wants to merge 1 commit into
scikit-learn:mainfrom
wmin401:fix-27682

Conversation

@wmin401

@wmin401 wmin401 commented Feb 19, 2024

Copy link
Copy Markdown

Reference Issues/PRs

Fixes #27317 from the issue "TST Extend tests for scipy.sparse.*array"

What does this implement/fix? Explain your changes.

My Implementation was to enhance the validation process for sparse containers by extending the existing tests to cover scipy.sparse.*array objects. This involves changing the parameter validation from "sparse matrix" to "sparse container" where necessary. The objective is was ensure that the validation process accurately reflects the capabilities of the codebase and handles sparse arrays appropriately.

Any other comments?

I am first-timer and It is my first PRs. If you give me a advice with my code, I would appreciate to you.

@github-actions

Copy link
Copy Markdown

❌ Linting issues

This PR is introducing linting issues. Here's a summary of the issues. Note that you can avoid having linting issues by enabling pre-commit hooks. Instructions to enable them can be found here.

You can see the details of the linting issues under the lint job here


black

black detected issues. Please run black . locally and push the changes. Here you can see the detected issues. Note that running black might also fix some of the issues which might be detected by ruff. Note that the installed black version is black=23.3.0.

Details

--- /home/runner/work/scikit-learn/scikit-learn/sklearn/utils/_param_validation.py	2024-02-19 03:14:37.831844 +0000
+++ /home/runner/work/scikit-learn/scikit-learn/sklearn/utils/_param_validation.py	2024-02-19 03:15:06.151789 +0000
@@ -543,11 +543,10 @@
 
 
 class _Callables(_Constraint):
     """Constraint representing callables."""
 
-
     def is_satisfied_by(self, val):
         return callable(val)
 
     def __str__(self):
         return "a callable"
@@ -858,11 +857,10 @@
 
     if isinstance(constraint, _RandomStates):
         if sp_version >= parse_version("1.8"):
             return sparse.csr_array([[0, 1], [1, 0]])
         return sparse.csr_matrix([[0, 1], [1, 0]])
-
 
     if isinstance(constraint, _Callables):
         return lambda x: x
 
     if isinstance(constraint, _NoneConstraint):
@@ -918,6 +916,6 @@
             if interval.type is Real:
                 return (interval.left + interval.right) / 2
             else:
                 return interval.left + 1
 
-    raise ValueError(f"Unknown constraint type: {constraint}")
\ No newline at end of file
+    raise ValueError(f"Unknown constraint type: {constraint}")
would reformat /home/runner/work/scikit-learn/scikit-learn/sklearn/utils/_param_validation.py
--- /home/runner/work/scikit-learn/scikit-learn/sklearn/utils/tests/test_param_validation.py	2024-02-19 03:14:37.835844 +0000
+++ /home/runner/work/scikit-learn/scikit-learn/sklearn/utils/tests/test_param_validation.py	2024-02-19 03:15:07.460322 +0000
@@ -791,6 +791,6 @@
         return get_config()["skip_parameter_validation"]
 
     with config_context(skip_parameter_validation=skip_parameter_validation):
         actual_skipped = g(1)
 
-    assert actual_skipped == expected_skipped
\ No newline at end of file
+    assert actual_skipped == expected_skipped
would reformat /home/runner/work/scikit-learn/scikit-learn/sklearn/utils/tests/test_param_validation.py

Oh no! 💥 💔 💥
2 files would be reformatted, 906 files would be left unchanged.

ruff

ruff detected issues. Please run ruff --fix --show-source . locally, fix the remaining issues, and push the changes. Here you can see the detected issues. Note that the installed ruff version is ruff=0.2.2.

Details

warning: The `--show-source` argument is deprecated. Use `--output-format=full` instead.
warning: The top-level linter settings are deprecated in favour of their counterparts in the `lint` section. Please update the following options in `pyproject.toml`:
  - 'ignore' -> 'lint.ignore'
  - 'select' -> 'lint.select'
  - 'per-file-ignores' -> 'lint.per-file-ignores'
sklearn/utils/_param_validation.py:1:1: I001 [*] Import block is un-sorted or un-formatted
   |
 1 | / import functools
 2 | | import math
 3 | | import operator
 4 | | import re
 5 | | import warnings
 6 | | from abc import ABC, abstractmethod
 7 | | from collections.abc import Iterable
 8 | | from inspect import signature
 9 | | from numbers import Integral, Real
10 | | 
11 | | import numpy as np
12 | | from scipy import sparse
13 | | from scipy.sparse import issparse, isspmatrix
14 | | from .._config import config_context, get_config
15 | | from .fixes import parse_version, sp_version
16 | | from .validation import _is_arraylike_not_scalar
17 | | 
18 | | 
19 | | class InvalidParameterError(ValueError, TypeError):
   | |_^ I001
20 |       """Custom exception to be raised when the parameter of a class/method/function
21 |       does not have a valid type or value.
   |
   = help: Organize imports

sklearn/utils/_param_validation.py:13:36: F401 [*] `scipy.sparse.isspmatrix` imported but unused
   |
11 | import numpy as np
12 | from scipy import sparse
13 | from scipy.sparse import issparse, isspmatrix
   |                                    ^^^^^^^^^^ F401
14 | from .._config import config_context, get_config
15 | from .fixes import parse_version, sp_version
   |
   = help: Remove unused import: `scipy.sparse.isspmatrix`

sklearn/utils/_param_validation.py:923:63: W292 [*] No newline at end of file
    |
921 |                 return interval.left + 1
922 | 
923 |     raise ValueError(f"Unknown constraint type: {constraint}")
    |                                                                W292
    |
    = help: Add trailing newline

sklearn/utils/tests/test_param_validation.py:796:46: W292 [*] No newline at end of file
    |
794 |         actual_skipped = g(1)
795 | 
796 |     assert actual_skipped == expected_skipped
    |                                               W292
    |
    = help: Add trailing newline

Found 4 errors.
[*] 4 fixable with the `--fix` option.

Generated for commit: 26a9de8. Link to the linter CI: here

@Charlie-XIAO

Charlie-XIAO commented Feb 21, 2024 •

Copy link
Copy Markdown
Contributor

Sorry @wmin401 but I'm going to close this in favor of #27950. The reason why #27950 is pending is because it involves something non-trivial and needs further discussion.

It seems that there are not many "good first issues" to work on at this moment, but you may look at "help wanted" to see if there is something you can help with.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants