10000 TST Extend tests for `scipy.sparse.*array` in `sklearn/feature_selection/tests/test_base.py` by znb899 · Pull Request #27325 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

TST Extend tests for scipy.sparse.*array in sklearn/feature_selection/tests/test_base.py #27325

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

Closed
wants to merge 1 commit into from

Conversation

znb899
Copy link
@znb899 znb899 commented Sep 9, 2023

What does this implement/fix? Explain your changes.

This PR introduces sparse containers' list conditionally to the version of SciPy

Any other comments?

Towards #27090

@github-actions
Copy link
github-actions bot commented Sep 9, 2023

❌ 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.


--- /home/runner/work/scikit-learn/scikit-learn/sklearn/feature_selection/tests/test_base.py	2023-09-09 21:16:26.745383 +0000
+++ /home/runner/work/scikit-learn/scikit-learn/sklearn/feature_selection/tests/test_base.py	2023-09-09 21:16:44.916786 +0000
@@ -3,10 +3,11 @@
 from numpy.testing import assert_array_equal
 
 from sklearn.base import BaseEstimator
 from sklearn.feature_selection._base import SelectorMixin
 from sklearn.utils.fixes import CSR_CONTAINERS
+
 
 class StepSelector(SelectorMixin, BaseEstimator):
     """Retain every `step` features (beginning with 0).
 
     If `step < 1`, then no features are selected.
@@ -100,11 +101,13 @@
     Xinv_actual = sel.fit(csr_container(X)).inverse_transform(csr_container(Xt))
     assert_array_equal(Xinv, Xinv_actual.toarray())
 
     # Check dtype matches
     assert np.int32 == sel.inverse_transform(csr_container(Xt).astype(np.int32)).dtype
-    assert np.float32 == sel.inverse_transform(csr_container(Xt).astype(np.float32)).dtype
+    assert (
+        np.float32 == sel.inverse_transform(csr_container(Xt).astype(np.float32)).dtype
+    )
 
     # Check wrong shape raises error
     with pytest.raises(ValueError):
         sel.inverse_transform(np.array([[1], [2]]))
 
would reformat /home/runner/work/scikit-learn/scikit-learn/sklearn/feature_selection/tests/test_base.py

Oh no! 💥 💔 💥
1 file would be reformatted, 905 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.0.287.


sklearn/feature_selection/tests/test_base.py:1:1: I001 [*] Import block is un-sorted or un-formatted
   |
 1 | / import numpy as np
 2 | | import pytest
 3 | | from numpy.testing import assert_array_equal
 4 | | 
 5 | | from sklearn.base import BaseEstimator
 6 | | from sklearn.feature_selection._base import SelectorMixin
 7 | | from sklearn.utils.fixes import CSR_CONTAINERS
 8 | | 
 9 | | class StepSelector(SelectorMixin, BaseEstimator):
   | |_^ I001
10 |       """Retain every `step` features (beginning with 0).
   |
   = help: Organize imports

sklearn/feature_selection/tests/test_base.py:65:25: F821 Undefined name `csr_container`
   |
63 | def test_transform_sparse():
64 |     sel = StepSelector()
65 |     Xt_actual = sel.fit(csr_container(X)).transform(csr_container(X))
   |                         ^^^^^^^^^^^^^ F821
66 |     Xt_actual2 = sel.fit_transform(csr_container(X))
67 |     assert_array_equal(Xt, Xt_actual.toarray())
   |

sklearn/feature_selection/tests/test_base.py:65:53: F821 Undefined name `csr_container`
   |
63 | def test_transform_sparse():
64 |     sel = StepSelector()
65 |     Xt_actual = sel.fit(csr_container(X)).transform(csr_container(X))
   |                                                     ^^^^^^^^^^^^^ F821
66 |     Xt_actual2 = sel.fit_transform(csr_container(X))
67 |     assert_array_equal(Xt, Xt_actual.toarray())
   |

sklearn/feature_selection/tests/test_base.py:66:36: F821 Undefined name `csr_container`
   |
64 |     sel = StepSelector()
65 |     Xt_actual = sel.fit(csr_container(X)).transform(csr_container(X))
66 |     Xt_actual2 = sel.fit_transform(csr_container(X))
   |                                    ^^^^^^^^^^^^^ F821
67 |     assert_array_equal(Xt, Xt_actual.toarray())
68 |     assert_array_equal(Xt, Xt_actual2.toarray())
   |

sklearn/feature_selection/tests/test_base.py:71:38: F821 Undefined name `csr_container`
   |
70 |     # Check dtype matches
71 |     assert np.int32 == sel.transform(csr_container(X).astype(np.int32)).dtype
   |                                      ^^^^^^^^^^^^^ F821
72 |     assert np.float32 == sel.transform(csr_container(X).astype(np.float32)).dtype
   |

sklearn/feature_selection/tests/test_base.py:72:40: F821 Undefined name `csr_container`
   |
70 |     # Check dtype matches
71 |     assert np.int32 == sel.transform(csr_container(X).astype(np.int32)).dtype
72 |     assert np.float32 == sel.transform(csr_container(X).astype(np.float32)).dtype
   |                                        ^^^^^^^^^^^^^ F821
73 | 
74 |     # Check wrong shape raises error
   |

sklearn/feature_selection/tests/test_base.py:100:27: F821 Undefined name `csr_container`
    |
 98 | def test_inverse_transform_sparse():
 99 |     sel = StepSelector()
100 |     Xinv_actual = sel.fit(csr_container(X)).inverse_transform(csr_container(Xt))
    |                           ^^^^^^^^^^^^^ F821
101 |     assert_array_equal(Xinv, Xinv_actual.toarray())
    |

sklearn/feature_selection/tests/test_base.py:100:63: F821 Undefined name `csr_container`
    |
 98 | def test_inverse_transform_sparse():
 99 |     sel = StepSelector()
100 |     Xinv_actual = sel.fit(csr_container(X)).inverse_transform(csr_container(Xt))
    |                                                               ^^^^^^^^^^^^^ F821
101 |     assert_array_equal(Xinv, Xinv_actual.toarray())
    |

sklearn/feature_selection/tests/test_base.py:104:46: F821 Undefined name `csr_container`
    |
103 |     # Check dtype matches
104 |     assert np.int32 == sel.inverse_transform(csr_container(Xt).astype(np.int32)).dtype
    |                                              ^^^^^^^^^^^^^ F821
105 |     assert np.float32 == sel.inverse_transform(csr_container(Xt).astype(np.float32)).dtype
    |

sklearn/feature_selection/tests/test_base.py:105:48: F821 Undefined name `csr_container`
    |
103 |     # Check dtype matches
104 |     assert np.int32 == sel.inverse_transform(csr_container(Xt).astype(np.int32)).dtype
105 |     assert np.float32 == sel.inverse_transform(csr_container(Xt).astype(np.float32)).dtype
    |                                                ^^^^^^^^^^^^^ F821
106 | 
107 |     # Check wrong shape raises error
    |

sklearn/feature_selection/tests/test_base.py:105:89: E501 Line too long (90 > 88 characters)
    |
103 |     # Check dtype matches
104 |     assert np.int32 == sel.inverse_transform(csr_container(Xt).astype(np.int32)).dtype
105 |     assert np.float32 == sel.inverse_transform(csr_container(Xt).astype(np.float32)).dtype
    |                                                                                         ^^ E501
106 | 
107 |     # Check wrong shape raises error
    |

Found 11 errors.
[*] 1 potentially fixable with the --fix option.

Generated for commit: fdd9bda. Link to the linter CI: here

@znb899 znb899 changed the title TST Extend tests for scipy.sparse.*array in TST Extend tests for scipy.sparse.*array in sklearn/feature_selection/tests/test_base.py Sep 9, 2023
@glemaitre glemaitre self-requested a review September 11, 2023 16:27
@glemaitre
Copy link
Member

This file was already changed in #27175

@glemaitre glemaitre closed this Sep 11, 2023
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
0